NULL
DraftNULL means missing or unknown. That makes it different from an empty string, zero, or false, and it changes how comparisons work.
Find missing values
Use IS NULL because NULL means unknown, not equal to a value.
Loaded Database:null.database-init
SELECT id, title
FROM tickets
WHERE assignee IS NULL;| id | title |
|---|---|
| 2 | Write docs |
Seq Scan on tickets (cost=0.00..18.10 rows=4 width=36)
Filter: (assignee IS NULL)Replace NULL for display
COALESCE returns the first non-NULL value from its arguments.
Loaded Database:null.database-init
SELECT title, COALESCE(assignee, 'Unassigned') AS owner
FROM tickets
ORDER BY id;| title | owner |
|---|---|
| Fix signup | Ada |
| Write docs | Unassigned |
| Close billing bug | Grace |
Sort (cost=57.23..59.26 rows=810 width=68)
Sort Key: id
-> Seq Scan on tickets (cost=0.00..18.10 rows=810 width=68)NULL is not equal
A comparison with NULL does not return true, so this query finds nothing.
Loaded Database:null.database-init
SELECT id, title
FROM tickets
WHERE assignee = NULL;No rows
Result (cost=0.00..0.00 rows=0 width=0)
One-Time Filter: false