subselects in the target list - Mailing list pgsql-hackers

From Neil Conway
Subject subselects in the target list
Date
Msg-id 1107403334.26960.38.camel@localhost.localdomain
Whole thread Raw
Responses Re: subselects in the target list
List pgsql-hackers
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




pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: libpq API incompatibility between 7.4 and 8.0
Next
From: Alvaro Herrera
Date:
Subject: Re: pg_dump bug in 7.3.9 with sequences