Re: return setof : alternatives to holder table

From: Joe Conway <mail(at)joeconway(dot)com>
To: zhong ming wu <mr(dot)z(dot)m(dot)wu(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: return setof : alternatives to holder table
Date: 2010-08-15 15:57:11
Message-ID: 4C680E57.4050102@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 08/15/2010 07:57 AM, zhong ming wu wrote:
> Here is what I have tried
>
> create or replace function te(out a int,out b int) returns setof record as
> $pgsql$
> declare
> r record;
> begin
> r.a := 1;
> r.b := 2;
> return next;
> end;
> $pgsql$ language plpgsql;

Try:

create or replace function te(out a int,out b int)
returns setof record as $pgsql$
begin
a := 1;
b := 2;
return next;
end;
$pgsql$ language plpgsql;

contrib_regression=# select * from te();
a | b
---+---
1 | 2
(1 row)

-- or --

create or replace function te()
returns TABLE(a int, b int) as $pgsql$
begin
a := 1;
b := 2;
return next;
end;
$pgsql$ language plpgsql;

contrib_regression=# select * from te();
a | b
---+---
1 | 2
(1 row)

HTH,

Joe

--
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-08-15 16:05:08 Re: InitDB: Bad system call
Previous Message Torsten Zühlsdorff 2010-08-15 15:46:17 Re: InitDB: Bad system call