CASE/WHEN behavior with NULLS

Поиск
Список
Период
Сортировка
От Thalis Kalfigkopoulos
Тема CASE/WHEN behavior with NULLS
Дата
Msg-id CAEkCx9G7Zfa_OQCpJk4y84g8T3=YO0Hp02sVd+DP3hhp+0CaAw@mail.gmail.com
обсуждение исходный текст
Ответы Re: CASE/WHEN behavior with NULLS  (David Johnston <polobo@yahoo.com>)
Список pgsql-general
Hello all,

I have a query that presents a sum() where in some records it's NULL
because all members of the group are NULL.
I decided I wanted to see a pretty 0 instead of NULL since it fits the
logic of the app.

This didn't work as expected (the NULL's persisted):
...CASE sum(foo) WHEN NULL THEN 0 ELSE sum(foo) END...

Whereas changing it to:
...CASE WHEN sum(foo) IS NULL THEN 0 ELSE sum(foo) END...
it works as expected, substituting the sum()'s that are NULL to zeros.

Is that expected behavior? Do i misunderstand how CASE/WHEN works?

Running:  PostgreSQL 9.1.3 on i686-pc-linux-gnu, compiled by gcc (GCC)
3.4.6, 32-bit

TIA,
Thalis K.


В списке pgsql-general по дате отправления:

Предыдущее
От: Steve Atkins
Дата:
Сообщение: Re: "Too far out of the mainstream"
Следующее
От: Andrew Sullivan
Дата:
Сообщение: Re: "Too far out of the mainstream"