Re: Do function calls the cached?

From: Daniel Caldeweyher <dcalde(at)gmail(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Do function calls the cached?
Date: 2016-09-01 11:02:44
Message-ID: CADVnD3BPmVSkTGKQHE4Ssahdjw8-HmiGP7YR-vVC0sAZfU4oNg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks David,

Lateral did the trick:

CREATE VIEW with_keywords AS
SELECT x,y,z, keywords.a, keywords.b, keywords.c
FROM large_table l, LATERAL extract_keywords(l.*) keywords(a,b,c)

Regards,
Daniel

On Wed, Aug 31, 2016 at 6:46 AM, David G. Johnston <
david(dot)g(dot)johnston(at)gmail(dot)com> wrote:

> On Tue, Aug 30, 2016 at 4:15 PM, Daniel Caldeweyher <dcalde(at)gmail(dot)com>
> wrote:
>
>>
>> select x,y,z, (extract_keywords(l.*)).*
>>
>> ​[...]​
>
>
>> Does this mean the function gets called three time?
>>
>
> ​Yes.
> ​
>
> (​function_call(...)).*​
>
> ​syntax is problematic. You should avoid it via one of two options.
>
> LATERAL (new way, preferred)
> or
> CTE​ (old way)
>
> In the CTE version you make the call in the CTE but do "(col).*" in the
> main query. This way the function is only called once to generate a
> composite output, then the composite output is exploded.
>
> With LATERAL the system is smart enough to do it the right way.
>
> David J.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2016-09-01 11:48:53 Re: Array element foreign keys
Previous Message Szymon Lipiński 2016-09-01 09:29:06 Re: COL unique (CustomerID) plus COL unique (COUNT) inside CustomerID