pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problem with returning setof record
2+ messages / 2 participants
[nested] [flat]

* Problem with returning setof record
@ 2004-09-07 17:13 oliverp21@free.fr
  2004-09-07 17:35 ` Re: Problem with returning setof record Richard Huxton <dev@archonet.com>
  0 siblings, 1 reply; 2+ messages in thread

From: oliverp21@free.fr @ 2004-09-07 17:13 UTC (permalink / raw)
  To: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Problem with returning setof record
  2004-09-07 17:13 Problem with returning setof record oliverp21@free.fr
@ 2004-09-07 17:35 ` Richard Huxton <dev@archonet.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Huxton @ 2004-09-07 17:35 UTC (permalink / raw)
  To: oliverp21@free.fr; +Cc: pgsql-sql

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-09-07 17:35 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-09-07 17:13 Problem with returning setof record oliverp21@free.fr
2004-09-07 17:35 ` Richard Huxton <dev@archonet.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox