Re: Selecting from a function(x,y) returning a row-type(sum, prod) - Mailing list pgsql-general

From Heiko Klein
Subject Re: Selecting from a function(x,y) returning a row-type(sum, prod)
Date
Msg-id 46383A4C.80409@gmx.net
Whole thread Raw
In response to Re: Selecting from a function(x,y) returning a row-type(sum, prod)  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Thanks,

my real function is quite expensive, so I don't want it to execute
twice. Toms subselect query is therefore exactly what I want, and since
it will be hidden in a view, it doesn't matter that it is a long expression.

Best regards,

Heiko

Tom Lane wrote:

> regression=# select x,y,(f).* from
> regression-#   (select *, sum_n_product(x,y) as f from myvals offset 0) ss;
>  x | y | sum | prod
> ---+---+-----+------
>  1 | 2 |   3 |    2
> (1 row)
>
> The "offset 0" is an optimization fence to keep the planner from
> flattening this form into the form where the function is called twice.
> (As of 8.2, you can dispense with that if the function is marked volatile.)
>

pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: STDERR vs. SYSLOG logging
Next
From: Richard Huxton
Date:
Subject: Re: Postgres (selection of thesis topic)