NULL and Three-Valued Logic
What NULL is not
NULL is not the empty string, zero, or the boolean false. NULL is a place-holder, not a value. NULL is not a member of any domain (type).
Three-valued logic
Because NULL represents “we don’t know”, we need three-valued logic (3VL). Let (or UNKNOWN) represent the third truth value. The truth tables extend Boolean logic:
AND ()
OR ()
NOT ()
| Result | |
|---|---|
Key observations:
- (one false makes the conjunction false, regardless of unknowns).
- (one true makes the disjunction true).
- (the negation of unknown is unknown).
Unexpected NULL behaviour
NULL can lead to surprising results:
SELECT * FROM students WHERE age <> 19;
This does not return rows where age IS NULL. Any comparison with NULL yields , and only rows where the WHERE clause evaluates to are included in the result. A row where age IS NULL evaluates age <> 19 to , which is not , so the row is excluded.
Interpretations of NULL
There are several possible interpretations of NULL, creating what the lecture calls “a great deal of semantic muddle”:
| Interpretation | Meaning |
|---|---|
| Missing value | There is a value, but we don’t know what it is |
| Inapplicable | No value is applicable (e.g., spouse for an unmarried person) |
| Hidden value | The value exists but you are not allowed to see it |
SQL’s definition
SQL’s definition: “NULL is not equal to anything — not even to another NULL.” This avoids the “common sister” paradox where two rows with unknown values could be spuriously equated.
The IS NULL predicate
IS NULL is the standard way to test for NULL. Unlike comparisons, IS NULL evaluates to either or — never :
SELECT * FROM students WHERE age IS NULL;
Similarly, IS NOT NULL returns or .
The NULL controversy
C.J. Date (a prominent relational theorist) argues that NULLs and 3VL are “a serious mistake” that “have no place in the relational model.” His criticism: NULLs violate the relational model’s logical foundations and create subtle inconsistencies.
Defender argument: NULLs serve an important practical role in handling incomplete information. The flaws should be repaired rather than abandoning NULLs entirely.
SQL inconsistency: GROUP BY on NULLs
Consider a GROUP BY on a column that contains NULLs:
SELECT col, COUNT(*) FROM t GROUP BY col;
SQL treats all NULL values as equivalent for grouping purposes — they form a single group. This contradicts the principle that “NULL is not equal to anything — not even to another NULL.” Under the rule that , each NULL would belong to its own group, but SQL groups them together.
Summary
- NULL is a place-holder, not a value, and not a member of any domain.
- Three-valued logic extends boolean truth tables with (UNKNOWN).
- Comparisons with NULL produce ; only satisfies
WHERE. - Use
IS NULL/IS NOT NULLto test for NULL reliably. - NULL has multiple interpretations: missing, inapplicable, or hidden.
- C.J. Date criticises NULLs as a relational model violation.
GROUP BYinconsistently treats all NULLs as one group.