From: Tom Lane <tgl@sss.pgh.pa.us>
To: Denis Bucher <dbucher@niftycom.com>
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: Need help with embedded CASEs
Date: Wed, 07 Nov 2001 13:06:36 -0500
Message-ID: <5450.1005156396@sss.pgh.pa.us> (raw)
In-Reply-To: <5.1.0.14.0.20011107164717.03153940@mail.niftycom.com>
References: <5.1.0.14.0.20011107164717.03153940@mail.niftycom.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, dbucher@niftycom.com
Subject: Re: Need help with embedded CASEs
In-Reply-To: <5450.1005156396@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox