Sunday, June 22, 2008

Re: [pdxpug] Meeting recap - Logic and Databases with Jeff Davis

>>>>> "David" == David E Wheeler <david@kineticode.com> writes:

David> try=# select sum(coalesce(column1, 0)) FROM (values (1), (NULL)) t;
David> sum
David> -----
David> 1
David> (1 row)

David> Even if the above example works, I'd certainly recommend this version (unless
David> column1 is NOT NULL).

I'd argue that this is also wrong. You should not include "unknown" in your
sum, even with this trick. Just filter it out with WHERE where you can,
and rely on this "trick" only when filtering the rows is not an option.

If NULL should mean 0 for sums, then it should be a 0, not a NULL, in the
table.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

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

No comments: