The
select null + 0
is not the same as the
select sum(a) from a
statement.
Something equivalent would be
select sum(a) where a in (select null as a union select 1 as a)
In other words: As far as I understand it, sum() sums up all non null
values. In statement you have only one value, which happens to be null which
in return adds up to null. In your other statement you have one non null
value and sum returns the sum of this one value which is 1.
Detlef
-----Ursprungliche Nachricht-----
Von: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org]Im Auftrag von Jean-Christian
Imbeault
Gesendet: Montag, 14. Juli 2003 07:42
An: pgsql-general@postgresql.org
Betreff: [GENERAL] select null + 0 question
Why is it that "select null + 1" gives null but "select sum(a) from
table" where there are null entries returns an integer?
Shouldn't the sum() and "+" operators behave the same?
TAL=# select null + 0;
?column?
----------
(1 row)
TAL=# select * from a;
a
---
1
(3 rows)
TAL=# select sum(a) from a;
sum
-----
1
(1 row)
Thanks,
Jean-Christian Imbeault
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend