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

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: PL/pgSQL: How to return two columns and multiple rows
Дата
Msg-id CAKFQuwYpHh3vwJEV36wQRjR0yXnOikFmU0Ep=6TOfsUkMknZKg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: PL/pgSQL: How to return two columns and multiple rows  (Sven Geggus <lists@fuchsschwanzdomain.de>)
Список 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 по дате отправления:

Предыдущее
От: Sven Geggus
Дата:
Сообщение: Re: PL/pgSQL: How to return two columns and multiple rows
Следующее
От: Sven Geggus
Дата:
Сообщение: Re: PL/pgSQL: How to return two columns and multiple rows