This behavior seems inconsistent: neilc=# create table abc (a int, b int); CREATE TABLE neilc=# create function foo_abc() returns setof abc as 'select * from abc' language sql; CREATE FUNCTION neilc=# insert into abc values (5, 10); INSERT 17234 1 neilc=# insert into abc values (10, 20); INSERT 17235 1 neilc=# select a, foo_abc() from abc; a | foo_abc ----+--------- 5 | (5,10) 5 | (10,20) 10 | (5,10) 10 | (10,20) (4 rows) neilc=# select a, (select * from abc) from abc; ERROR: subquery must return only one column
Is there a reason we can't treat a subselect in the target list as returning a composite type? For that matter, is this behavior also intentional? neilc=# create function foo_abc2() returns setof abc as 'declare row record; begin for row in select * from abc loop return next row; end loop; return; end' language plpgsql; CREATE FUNCTION neilc=# select a, foo_abc2() FROM abc; ERROR: set-valued function called in context that cannot accept a set CONTEXT: PL/pgSQL function "foo_abc2" line 1 at return next -Neil ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org