Search Postgresql Archives

Re: CASE/WHEN behavior with NULLS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Johnston <polobo@xxxxxxxxx> writes:
> On Aug 31, 2012, at 19:14, Thalis Kalfigkopoulos <tkalfigo@xxxxxxxxx> 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


-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux