Re: Select CASE when null ?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Select CASE when null ?
Дата
Msg-id 22088.1231968784@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Select CASE when null ?  ("Camilo Sperberg" <unreal4u@chilehardware.com>)
Список 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 по дате отправления:

Предыдущее
От: "Camilo Sperberg"
Дата:
Сообщение: Re: Select CASE when null ?
Следующее
От: Jeff Davis
Дата:
Сообщение: Re: A better BETWEEN for DATEs, TIMEs and TIMESTAMPs?