In retrospect, has it been a good idea to use three-valued logic for SQL NULL comparisons?

Posted by Heinzi on Programmers See other posts from Programmers or by Heinzi
Published on 2013-11-07T22:05:59Z Indexed on 2013/11/07 22:17 UTC
Read the original article Hit count: 407

Filed under:
|
|
|
|

In SQL, NULL means "unknown value". Thus, every comparison with NULL yields NULL (unknown) rather than TRUE or FALSE.

From a conceptional point of view, this three-valued logic makes sense. From a practical point of view, every learner of SQL has, one time or another, made the classic WHERE myField = NULL mistake or learned the hard way that NOT IN does not do what one would expect when NULL values are present.

It is my impression (please correct me if I am wrong) that the cases where this three-valued logic helps (e.g. WHERE myField IS NOT NULL AND myField <> 2 can be shortened to WHERE myField <> 2) are rare and, in those cases, people tend to use the longer version anyway for clarity, just like you would add a comment when using a clever, non-obvious hack.

Is there some obvious advantage that I am missing? Or is there a general consensus among the development community that this has been a mistake?

© Programmers or respective owner

Related posts about database

Related posts about sql