Inspired by a StackOverflow question (Why doesn't SQL support "= null" instead of "is null"?).
Is there a DBMS that actually supports the = NULL syntax?
Inspired by a StackOverflow question (Why doesn't SQL support "= null" instead of "is null"?).
Is there a DBMS that actually supports the = NULL syntax?
Some implementations of SQL do recognise x = NULL as equality, the ISO/ANSI standard on the other hand does not. In SQL Server for instance, SET ANSI_NULLS OFF results in (NULL = NULL) = true.
SET ANSI_NULLS OFF
SELECT CASE WHEN NULL = NULL THEN 1 ELSE 0 END
SET ANSI_NULLS ON
SELECT CASE WHEN NULL = NULL THEN 1 ELSE 0 END
You can configure Postgres to see NULL=NULL as true. See the documentation on transform_null_equals for more details. End of Postgres specific part of the answer.
I do not recommend to use this setting to make NULL equal another NULL since NULL has the meaning of being unknown. As you don't know if two unknown things refer to the same object (value), comparing NULL with something should always result in NULL (comparison result is unknown). It would have been better to call NULL differently – for example UNKNOWN – but SQL chose not to do so.
If you want to see if something is unknown use thing is NULL.
If you want to see if two things are equal or both are NULL use thing1 is not distinct from thing2. See the page end of Postgre's comparison functions for more information on this syntax. Firebird's documentation on the matter also includes a table which shows sample comparisons and their results. Wikipedia has the tables as well. IBM's DB2 does also support the distinct predicate according to their documentation.
Unfortunately, it looks like neither Microsoft with SQL Server nor Oracle with MySQL do support it. For MySQL their is a similar feature written as <=>.
SQL 1999 defines a distinct predicate (ISO/IEC 9075-2:1999 (E), section 8.13) as follows (cases for array types not shown here, slightly reformatted due to this platform's restricted formatting support):
i) ‘‘X IS DISTINCT FROM Y’’ is false if either:
1) X and Y are the null value, or
2) X = Y according to Subclause 8.2, ‘‘comparison predicate’’.
ii) Otherwise, ‘‘X IS DISTINCT FROM Y’’ is true.
So for the negated case is not distinct from:
TRUE or FALSENULL it yields TRUENULL it yields FALSE=second value.You have to remember that NULL isn't a constant, but rather is an unknown. You can't be equal to an unknown because you don't know the value of NULL.
null is treated than what null "is"
– Jack Douglas
Aug 20 '11 at 10:50
There's a possible answer that 'all SQL DBMS support = NULL', but that is true in the SET clause of an UPDATE statement, not in a context that requires a conditional. That context would not accept IS NULL of course (you could not write SET SomeCol IS NULL).
= NULL compared to IS NULL. Setting a value to NULL is ANSI standard. As you mention, all DBMSs allow that, but that's not what the question is about.
– Richard
Aug 20 '11 at 19:34
null and because to my mind you answered the question "Is there a DBMS that allows the "= NULL" syntax?"
– Jack Douglas
Aug 23 '11 at 19:27