From: | merlyn(at)stonehenge(dot)com (Randal L(dot) Schwartz) |
---|---|
To: | "David E(dot) Wheeler" <david(at)kineticode(dot)com> |
Cc: | PDX PostgreSQL Users <pdxpug(at)postgresql(dot)org> |
Subject: | Re: Meeting recap - Logic and Databases with Jeff Davis |
Date: | 2008-06-22 18:31:01 |
Message-ID: | 867ichiaoq.fsf@blue.stonehenge.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pdxpug |
>>>>> "David" == David E Wheeler <david(at)kineticode(dot)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(at)stonehenge(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Davis | 2008-06-23 00:16:54 | Re: Meeting recap - Logic and Databases with Jeff Davis |
Previous Message | Jeff Davis | 2008-06-22 17:49:49 | Re: Meeting recap - Logic and Databases with Jeff Davis |