Isdistinct
Isdistinct is an operator used in SQL to compare two values in a NULL-safe way. It corresponds to the SQL standard operator IS DISTINCT FROM and is designed to yield a definite boolean result even when NULLs are involved. The operator returns true when the two expressions are not equal, or when exactly one of the operands is NULL; it returns false when the operands are equal or both are NULL. This behavior contrasts with the usual inequality operator (<>, !=), which can yield unknown (NULL) when either side is NULL, complicating predicate logic in WHERE clauses and JOIN conditions.
In practice, the semantics can be summarized as: a IS DISTINCT FROM b is true if a
- SELECT 5 IS DISTINCT FROM 5; returns false
- SELECT 5 IS DISTINCT FROM 7; returns true
- SELECT NULL IS DISTINCT FROM NULL; returns false
- SELECT NULL IS DISTINCT FROM 1; returns true
Emulation in systems that do not support IS DISTINCT FROM can be achieved with a composite predicate,
Support and usage vary by database system. PostgreSQL and other databases that adhere to the SQL standard
---