Re: Select CASE when null ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Camilo Sperberg" <unreal4u(at)chilehardware(dot)com>
Cc: "postgres list" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Select CASE when null ?
Date: 2009-01-14 21:33:04
Message-ID: 22088.1231968784@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Camilo Sperberg" <unreal4u(at)chilehardware(dot)com> writes:
> SELECT
> CASE mid WHEN NULL THEN CAST(0 AS integer)
> ELSE mid
> END AS mid,

BTW, the reason this doesn't work is the same reason "mid = NULL"
doesn't work, because that's exactly what the CASE condition is
treated as. The COALESCE trick is certainly the best solution
for this specific need, but the more general way would be

CASE WHEN mid IS NULL THEN ... ELSE ...

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Davis 2009-01-14 21:35:42 Re: A better BETWEEN for DATEs, TIMEs and TIMESTAMPs?
Previous Message Camilo Sperberg 2009-01-14 21:23:10 Re: Select CASE when null ?