If I try to create a column whose value is a selection that returns more than one row, I get an error.
=> select (select 1 union select 2); ERROR: more than one row returned by a subquery used as an expression
But if I create a function that does the same, I get the behavior that I want.
=> create or replace function onetwo() returns setof integer as $$ $> select 1 union select 2 $> $$ language 'sql' strict immutable; CREATE FUNCTION => select onetwo(); onetwo -------- 1 2
Why is the difference?
function sql postgresql subquery
Russell Silva
source share