-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Error in handling of NULL values when used with NOT IN #3767
Copy link
Copy link
Closed
Labels
bugConfirmed user-visible misbehaviour in official releaseConfirmed user-visible misbehaviour in official releasecomp-datatype-wrapperType modifiers/wrappers (Nullable, LowCardinality, etc.).Type modifiers/wrappers (Nullable, LowCardinality, etc.).sql-compatibility
Description
I'm using version 18.14.18, and I get the following unexpected behavior.
- CREATE TABLE null_test (value Nullable(String)) ENGINE=Memory;
- INSERT INTO null_test (value) VALUES ('A String'), (NULL);
- SELECT value FROM null_test WHERE value NOT IN ('A String');
The SELECT statement returns the row with the NULL value.
┌─value─┐ │ ᴺᵁᴸᴸ │ └───────┘
My expectation was that it should return no rows. I believe the predicate for the row with a value of NULL should reduce as follows based on SQL's three-valued logic:
value NOT IN ('A String')
-> NULL NOT IN ('A String')
-> NOT (NULL IN ('A String'))
-> NOT (NULL = 'A String')
-> NOT (Unknown)
-> Unknown;
A final value of Unknown for the predicate should then be interpreted as false when deciding if the row should be included in the result set.
Please let me know if you need any more information or if I'm missing something. Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugConfirmed user-visible misbehaviour in official releaseConfirmed user-visible misbehaviour in official releasecomp-datatype-wrapperType modifiers/wrappers (Nullable, LowCardinality, etc.).Type modifiers/wrappers (Nullable, LowCardinality, etc.).sql-compatibility