Re: PL/pgSQL: How to return two columns and multiple rows

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: rod(at)iol(dot)ie
Cc: Sven Geggus <lists(at)fuchsschwanzdomain(dot)de>, pgsql-general(at)postgresql(dot)org
Subject: Re: PL/pgSQL: How to return two columns and multiple rows
Date: 2015-06-18 13:03:01
Message-ID: 3271.1434632581@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Raymond O'Donnell" <rod(at)iol(dot)ie> writes:
> On 18/06/2015 13:36, Sven Geggus wrote:
>> I would like to be able to do something like this:
>>
>> select myfunc('foo','bar');
>> or
>> select myfunc(foo, bar) from foobartable;
>> or even
>> select myfunc(foo, bar), 'baz' as baz from foobartable;

> You need to do:

> select * from myfunc('foo','bar');

That's enough to expand the output from a simple function call. If you
want to do something like Sven's later examples, the best way is with
LATERAL:

select f.*, 'baz' as baz from foobartable, lateral myfunc(foo, bar) as f;

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2015-06-18 13:10:13 Re: PL/pgSQL: How to return two columns and multiple rows
Previous Message Raymond O'Donnell 2015-06-18 12:54:42 Re: PL/pgSQL: How to return two columns and multiple rows