Re: Referencing function value inside CASE..WHEN - Mailing list pgsql-general

From Pavel Stehule
Subject Re: Referencing function value inside CASE..WHEN
Date
Msg-id BANLkTi=JfZT1giqPgC7SfR7gp+3+3PMRqw@mail.gmail.com
Whole thread Raw
In response to Referencing function value inside CASE..WHEN  (lover boi <lover-boi@live.co.uk>)
List pgsql-general
Hello

2011/6/19 lover boi <lover-boi@live.co.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.

pgsql-general by date:

Previous
From: David Boreham
Date:
Subject: Re: Another RAID controller recommendation question
Next
From: Craig Ringer
Date:
Subject: Re: Port forwarding via iptables to postgres listening locally