3 ms·
A: "I want to add 2 numbers" B: "Ok, what's the first number?" A: "1" B: "Ok, what's the second number?" A: "I dont know..." B: "Then I dont know the answer..."
by manigandham 9y ago
A: "I want to add 2 numbers"
B: "Ok, what's the first number?"
A: "1"
B: "Ok, what's the second number?"
A: "I dont know..."
B: "Then I dont know the answer..."
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.
- dllthomas 9y agopostgres=# SELECT AVG(x) FROM (SELECT 1 AS x UNION SELECT NULL) t; avg ------------------------ 1.00000000000000000000 (1 row)
- willtim 9y ago> NULL is the absence of a value. It has no meaning in algebra. 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.