| От | Tom Lane |
|---|---|
| Тема | Re: CASE/WHEN behavior with NULLS |
| Дата | |
| Msg-id | 28068.1346464339@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | Re: CASE/WHEN behavior with NULLS (David Johnston <polobo@yahoo.com>) |
| Ответы |
Re: CASE/WHEN behavior with NULLS
|
| Список | pgsql-general |
David Johnston <polobo@yahoo.com> writes:
> On Aug 31, 2012, at 19:14, Thalis Kalfigkopoulos <tkalfigo@gmail.com> wrote:
>> This didn't work as expected (the NULL's persisted):
>> ...CASE sum(foo) WHEN NULL THEN 0 ELSE sum(foo) END...
> Guessing this form effectively evaluates to
> WHEN sum(foo) = NULL instead of IS NULL and thus the wrong answer:
Yeah, I think that's right.
> That said you might want to try
> SUM(COALESCE(foo, 0))
Actually I'd go with "COALESCE(SUM(foo), 0)" since that requires only
one COALESCE operation, not one per row.
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера