sql / expert
Snippet
Null-Safe Equality using IS NOT DISTINCT FROM
In standard SQL, NULL comparisons result in UNKNOWN. The IS NOT DISTINCT FROM predicate treats NULL as a comparable value, allowing it to return TRUE if both operands are NULL, or if both are equal non-null values.
snippet.sql
1
2
3
SELECT *FROM inventoryWHERE current_stock IS NOT DISTINCT FROM restock_threshold;
Breakdown
1
current_stock
The first column operand, which may contain NULL values.
2
IS NOT DISTINCT FROM
A null-safe comparison operator that handles 3-valued logic as binary TRUE/FALSE by treating NULLs as equal to each other.
3
restock_threshold
The second operand to compare against the first.