Skip to content

Error in handling of NULL values when used with NOT IN #3767

@ketbra

Description

@ketbra

I'm using version 18.14.18, and I get the following unexpected behavior.

  1. CREATE TABLE null_test (value Nullable(String)) ENGINE=Memory;
  2. INSERT INTO null_test (value) VALUES ('A String'), (NULL);
  3. 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!

Metadata

Metadata

Assignees

Labels

bugConfirmed user-visible misbehaviour in official releasecomp-datatype-wrapperType modifiers/wrappers (Nullable, LowCardinality, etc.).sql-compatibility

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions