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 CAKFQuwZbxsifWoG_ft=EzjnQaPS1DBiEN7X52152SLwoX-CY2Q@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:52 AM, Sven Geggus <lists@fuchsschwanzdomain.de> wrote:
Raymond O'Donnell <rod@iol.ie> wrote:

>> mydb=> select myfunc('foo','bar');
>
> You need to do:
>
>    select * from myfunc('foo','bar');

This has been a misguided example. Reality should more likely look like this:

select myfunc(col1,col2) from mytable;

And it would of course be undesired if myfunc would be called twice per row.
So how would this look like to avoid the function beeing called twice?

​WITH exec_func AS ( SELECT myfunc(col1,col2) FROM mytable )
SELECT (exec_func.myfunc).* FROM exec_func;

This relies on the fact that currently a CTE introduces an optimization barrier.

David J.
 

В списке pgsql-general по дате отправления:

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