Re: Select CASE when null ? - Mailing list pgsql-general

From Tom Lane
Subject Re: Select CASE when null ?
Date
Msg-id 22088.1231968784@sss.pgh.pa.us
Whole thread Raw
In response to Select CASE when null ?  ("Camilo Sperberg" <unreal4u@chilehardware.com>)
List pgsql-general
"Camilo Sperberg" <unreal4u@chilehardware.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

pgsql-general by date:

Previous
From: "Camilo Sperberg"
Date:
Subject: Re: Select CASE when null ?
Next
From: Jeff Davis
Date:
Subject: Re: A better BETWEEN for DATEs, TIMEs and TIMESTAMPs?