如果我尝试创建一个值为select的返回多行的列,则会出现错误.
=> select (select 1 union select 2); ERROR: more than one row returned by a subquery used as an expression
但是如果我创建一个执行相同操作的函数,我会得到我想要的行为.
=> 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
为什么不同?