Re: Evaluate only one CASE WHEN in a select

From: "dcrespo" <dcrespo(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Evaluate only one CASE WHEN in a select
Date: 2007-04-12 18:22:42
Message-ID: 1176402162.885774.159630@o5g2000hsb.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Apr 11, 11:35 pm, guyr-(dot)(dot)(dot)(at)burntmail(dot)com (Guy Rouillier) wrote:
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq- Hide quoted text -
>
> - Show quoted text -

They are exactly the same, that's why I want to evaluate it only once
and, depending on it, put the corresponding value into two different
fields that must be returned, instead of evaluating once for each
field. Any insight?

Thank you

Daniel

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Fischer 2007-04-12 18:27:11 Bugs not appearing in list archives
Previous Message Alvaro Herrera 2007-04-12 18:17:19 Re: SQL - finding next date