Re: returns setof rec... simple exampe doesn't work

From: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>
To: "Gauthier, Dave" <dave(dot)gauthier(at)intel(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: returns setof rec... simple exampe doesn't work
Date: 2007-07-13 03:36:28
Message-ID: D7FF158337303A419CF4A183F48302D602D531E4@hdsmsx411.amr.corp.intel.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I'll answer my own question...

select * from myfunc();

(dumb, dumb, dumb....)

-dave

________________________________

From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Gauthier, Dave
Sent: Monday, July 09, 2007 4:07 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] returns setof rec... simple exampe doesn't work

I've googled this one and tried everything (except the correct solution
of course) until tears are starting to flow. Please help. Complete
example below. 7.4.13 on suse-64 x86

create table mytable (mystring varchar, myreal real);

insert into mytable (mystring,myreal) values ('abc',1.23);

insert into mytable (mystring,myreal) values ('def',4.56);

create type myrec as (mystring varchar, myreal real);

create or replace function myfunc() returns setof myrec as '

declare

crec myrec;

begin

for crec in select * from mytable loop

return next crec;

end loop;

return;

end;

' language 'plpgsql';

stdb=# select myfunc();

ERROR: set-valued function called in context that cannot accept a set

CONTEXT: PL/pgSQL function "myfunc" line 6 at return next

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert Treat 2007-07-13 03:37:26 Re: One Large Table or Multiple DBs?
Previous Message Ron Johnson 2007-07-13 03:00:55 Re: One Large Table or Multiple DBs?