Consider this T-SQL:
DECLARE @ColorID INT
SET @ColorID = 3
SELECT *, left(name,3)
FROM Products p
WHERE ColorID = @ColorID
This works, but does not declare a variable:
SELECT *, substring(name,1,3)
FROM Products p
WHERE ColorID = 3
I tried this:
DO $$
DECLARE ColorID INT;
BEGIN
ColorID := 3;
SELECT *, substring(name,1,3)
FROM Products p
WHERE ColorID = ColorID
END$$;
He wants me to define a set of results. I do not want to do this because it continues to change as I am just studying the data.
ERROR: query has no destination for result data
I tried the "return query" but then got the following error:
ERROR: cannot use RETURN QUERY in a non-SETOF function
So, I want to return a few lines without specifying what the result set should look like. Using PostgreSQL 9.4.4
source
share