Re: Referencing function value inside CASE..WHEN

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: lover boi <lover-boi(at)live(dot)co(dot)uk>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Referencing function value inside CASE..WHEN
Date: 2011-06-19 08:20:42
Message-ID: BANLkTi=JfZT1giqPgC7SfR7gp+3+3PMRqw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello

2011/6/19 lover boi <lover-boi(at)live(dot)co(dot)uk>:
> Hi,
>
> In the following statement, does the custom function get executed twice?
>
> SELECT
>   MY_FUNCTION(...),
>   CASE WHEN MY_FUNCTION(...) = '...' THEN '...' ELSE '...' END
> ...
> ...
>
>
> If so, is there a way I can make it execute once?  I tried this but it gave
> me a "Column my_function does not exist" error.
>

SELECT x, CASE WHEN x THEN .. ELSE .. END FROM (SELECT fce(..) x FROM foo) s;

Regards

Pavel Stehule

> SELECT
>
>   MY_FUNCTION(...) AS my_function,
>
>   CASE WHEN my_function = '...' THEN '...' ELSE '...' END
>
> ...
>
> ...
>
>
> Thank you in advance.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2011-06-19 09:21:26 Re: Port forwarding via iptables to postgres listening locally
Previous Message David Boreham 2011-06-19 06:33:04 Re: Another RAID controller recommendation question