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

From: Heiko Klein <Heiko(dot)Klein(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting from a function(x,y) returning a row-type(sum, prod)
Date: 2007-05-02 07:14:20
Message-ID: 46383A4C.80409@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.)
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-05-02 07:48:08 Re: Postgres (selection of thesis topic)
Previous Message David Fetter 2007-05-02 06:46:55 Re: STDERR vs. SYSLOG logging