For the following query
SELECT sum(c)
FROM (SELECT 1 c WHERE false) t;
I thought it takes the sum of zero numbers, and therefore should return 0. (Similarly, I expect, e.g. an array aggregate function to return an empty array on zero elements).
Yet, it is returning a NULL (using PostgreSQL 11).
=> SELECT sum(c) FROM (SELECT 1 c WHERE false) t;
sum
-----
(1 row)
This doesn't make sense to me logically.
Why is the sum of zero numbers (for any numeric type) not zero? Is this NULL returning behavior standard?
Or maybe I am missing something. Any reason one has to make the sum NULL in some corner cases?