Re: return setof : alternatives to holder table - Mailing list pgsql-general

From zhong ming wu
Subject Re: return setof : alternatives to holder table
Date
Msg-id AANLkTimUZ38iCGZ5Pk7soRT+GfFudD=q-sVnH78nq-EK@mail.gmail.com
Whole thread Raw
In response to return setof : alternatives to holder table  (zhong ming wu <mr.z.m.wu@gmail.com>)
List pgsql-general
On Sun, Aug 15, 2010 at 12:21 PM, zhong ming wu <mr.z.m.wu@gmail.com> wrote:
> On Sun, Aug 15, 2010 at 11:57 AM, Joe Conway <mail@joeconway.com> wrote:
>> 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)
>>
>

The second example is perfect in that I just need to insert my table
definition into function definition.  Thanks.

pgsql-general by date:

Previous
From: Torsten Zühlsdorff
Date:
Subject: Re: InitDB: Bad system call
Next
From: Tom Lane
Date:
Subject: Re: InitDB: Bad system call