Re: PL/pgSQL: How to return two columns and multiple rows - Mailing list pgsql-general

From David G. Johnston
Subject Re: PL/pgSQL: How to return two columns and multiple rows
Date
Msg-id CAKFQuwYpHh3vwJEV36wQRjR0yXnOikFmU0Ep=6TOfsUkMknZKg@mail.gmail.com
Whole thread Raw
In response to Re: PL/pgSQL: How to return two columns and multiple rows  (Sven Geggus <lists@fuchsschwanzdomain.de>)
List pgsql-general
On Thu, Jun 18, 2015 at 9:32 AM, Sven Geggus <lists@fuchsschwanzdomain.de> wrote:
David G. Johnston <david.g.johnston@gmail.com> wrote:

> Look at the "returns table (col1 type, col2 type)" form.

If I got this right "returns table" is not what I want as I need to select
from my function as a virtual table in this case.

​Yes, I mis-read your question.  Your issue is placing the SRF (set returning function) in the select-list which causes it to be treated as a single composite-typed column.  You need to place the function in after "FROM" or "LATERAL"

Something like:

SELECT * FROM src_tbl LATERAL my_func(src_tbl.col1, src_tbl.col2)​

I haven't had much experience writing lateral clauses but their benefit is that they can reference columns from other tables so you don't have to place the function in the select-list.

David J.

pgsql-general by date:

Previous
From: Sven Geggus
Date:
Subject: Re: PL/pgSQL: How to return two columns and multiple rows
Next
From: Sven Geggus
Date:
Subject: Re: PL/pgSQL: How to return two columns and multiple rows