Re: Need help with embedded CASEs - Mailing list pgsql-sql

From Tom Lane
Subject Re: Need help with embedded CASEs
Date
Msg-id 5450.1005156396@sss.pgh.pa.us
Whole thread Raw
In response to Need help with embedded CASEs  (Denis Bucher <dbucher@niftycom.com>)
List pgsql-sql
Denis Bucher <dbucher@niftycom.com> writes:
> SELECT CASE WHEN '2001-11-07' = current_date THEN 't' ELSE 'f' END AS 
> flag_today, CASE WHEN flag_today THEN current_time ELSE '00:00' END AS 
> time_iftoday;

> Why doesn't it work ?

flag_today is an output variable of this SELECT, not an input.

> Or how could I use the result of the CASE in another ?

AFAIK the only way to avoid writing the expression twice is to use
a sub-select:

SELECT ss.flag_today,      CASE WHEN ss.flag_today THEN current_time ELSE '00:00' END AS time_iftoday
FROM
(SELECT CASE WHEN '2001-11-07' = current_date THEN true ELSE false END AS 
flag_today) AS ss;
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: RIGHT JOIN is only supported with mergejoinable join conditions
Next
From: "Nick Fankhauser"
Date:
Subject: Re: RIGHT JOIN is only supported with mergejoinable join conditions