Re: Evaluate only one CASE WHEN in a select - Mailing list pgsql-general

From Guy Rouillier
Subject Re: Evaluate only one CASE WHEN in a select
Date
Msg-id 461DA91F.6040806@burntmail.com
Whole thread Raw
In response to Evaluate only one CASE WHEN in a select  ("dcrespo" <dcrespo@gmail.com>)
Responses Re: Evaluate only one CASE WHEN in a select  ("dcrespo" <dcrespo@gmail.com>)
List pgsql-general
dcrespo wrote:
> Hi everybody,
>
> I'm implementing something like this:
>
> SELECT
>     CASE WHEN add_numbers(t1.main_number,t2.main_number)>100
>         THEN t1.description1
>         ELSE t2.description1
>     END AS number_description1,
>     CASE WHEN add_numbers(t1.main_number,t2.main_number)>100
>         THEN t1.description2
>         ELSE t2.description2
>     END AS number_description2
> FROM table1 t1, table2 t2;
>
> Is there a way to evaluate the 'CASE WHEN' only once?

Sure, see the implementation of CASE here:

http://www.postgresql.org/docs/8.2/static/functions-conditional.html

Not sure what you are looking for, though, since your condition in both
CASEs above is exactly the same.

--
Guy Rouillier

pgsql-general by date:

Previous
From: marcelo Cortez
Date:
Subject: Re: 8.2.3 AutoVacuum not running
Next
From: "Leon Mergen"
Date:
Subject: hashtext () and collisions