Problem with returning setof record
am 07.09.2004 19:13:14 von oliverp21
Hello,
Here is a simple function I created for a test.
create function ttt() returns setof record as '
declare
r record;
begin
for r in select * from utilisateurs.menus loop
return next r;
end loop;
return;
end;
' language 'plpgsql';
When I try to use it, it returns to me :
select ttt();
set-valued function called in context that cannot accept a set
: PL/pgSQL function "ttt" line 5 at return next
Anyone has an idea ?
Best regards,
Patrice OLIVER
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster
Re: Problem with returning setof record
am 07.09.2004 19:35:51 von dev
oliverp21@free.fr wrote:
> Hello,
>
> Here is a simple function I created for a test.
>
> create function ttt() returns setof record as '
> When I try to use it, it returns to me :
>
> select ttt();
> set-valued function called in context that cannot accept a set
> : PL/pgSQL function "ttt" line 5 at return next
>
> Anyone has an idea ?
You need to treat it like a table:
SELECT * FROM ttt();
Also, I'm not sure you can return a setof anonymous record types (unless
you can specify the structure in the select).
Try CREATE FUNCTION...RETURNS SETOF utilisateurs.menus
If there's no appropriate table you can use CREATE TYPE to create a
structure.
--
Richard Huxton
Archonet Ltd
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org