by manigandham · 8y ago · 0 comments
NULL is the absence of a value. It has no meaning in algebra. You cannot do anything mathematically with a NULL value so it always results in a NULL output regardless of the operator. If you do use the numeric functions, then it will attempt to convert to a number (0) first. Where is the inconsistency?
It seems you want the database to automatically assume 0 for NULL when they are distinctly separate meanings and it would be far more confusing if that were so.
Null is a value in its own right. If null is added to e.g. the type of numbers, then it had better be given meaning (i.e. semantics).
> You cannot do anything mathematically with a NULL value so it always results in a NULL output
Returning null if any input is null seems reasonable, but again this is not true with SQL SUM: SUM [1, null] = 1.
> Where is the inconsistency
You seriously cannot see an inconsistency? Are you trolling?
> It seems you want the database to automatically assume 0 for NULL
Where on earth did you get that idea? You are defending the behaviour of SQL SUM, not me! I've already told you, I don't want coercions.
postgres=# SELECT AVG(x) FROM (SELECT 1 AS x UNION SELECT NULL) t;
avg
------------------------
1.00000000000000000000
(1 row)