From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Sven Geggus <lists(at)fuchsschwanzdomain(dot)de> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: PL/pgSQL: How to return two columns and multiple rows |
Date: | 2015-06-18 13:56:30 |
Message-ID: | CAKFQuwZbxsifWoG_ft=EzjnQaPS1DBiEN7X52152SLwoX-CY2Q@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Jun 18, 2015 at 9:52 AM, Sven Geggus <lists(at)fuchsschwanzdomain(dot)de>
wrote:
> Raymond O'Donnell <rod(at)iol(dot)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.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2015-06-18 14:01:46 | Re: writable cte triggers reverse order |
Previous Message | Sven Geggus | 2015-06-18 13:52:02 | Re: PL/pgSQL: How to return two columns and multiple rows |