- Categories:
IS [ NOT ] DISTINCT FROM¶
Compares whether two expressions are equal (or not equal). The function is NULL-safe, meaning it treats NULLs as known values for comparing equality. Note that this is different from the EQUAL
comparison operator (=), which treats NULLs as unknown values.
- See also:
Syntax¶
Usage notes¶
The value returned depends on whether any of the inputs are NULL values:
- Returns TRUE:
<null> IS NOT DISTINCT FROM <null><null> IS DISTINCT FROM <not_null><not_null> IS DISTINCT FROM <null>- Returns FALSE:
<null> IS DISTINCT FROM <null><null> IS NOT DISTINCT FROM <not_null><not_null> IS NOT DISTINCT FROM <null>
Otherwise:
<expr1> IS DISTINCT FROM <expr2>is equivalent to<expr1> != <expr2><expr1> IS NOT DISTINCT FROM <expr2>is equivalent to<expr1> = <expr2>
For more details, see the examples below.
Examples¶
Create a table with simple data:
Show the Cartesian product generated by joining the table to itself without a filter:
Return rows that contain:
Only equal values for both columns.
Only equal values or NULL values for both columns.
Illustrate all possible outcomes for:
EQUAL
=and NOT EQUAL<>IS NOT DISTINCT FROM and IS DISTINCT FROM