Re: Bug / Unexpected behaviour of NOT LIKE - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Bug / Unexpected behaviour of NOT LIKE
Date
Msg-id 4148675.1633539174@sss.pgh.pa.us
Whole thread Raw
In response to Bug / Unexpected behaviour of NOT LIKE  (Judith Meyer <yutian.mei@gmail.com>)
List pgsql-bugs
Judith Meyer <yutian.mei@gmail.com> writes:
> I believe that I have found a bug or at least an undocumented unexpected
> behaviour in the NOT LIKE operator (tested in PG 13). Namely, the query

> SELECT * FROM users WHERE comment NOT LIKE 'hello%';

> *never returns any users where the comment cell is empty, even though empty
> also isn't "hello%".* This caused bugs in several parts of my code and
> there is nothing about it in the documentation of the LIKE operator.

If by "empty" you mean NULL, this is expected and well documented.
"null LIKE something" returns NULL just like most other operations
on nulls, and then NOT (NULL) is also NULL, and both of those make
sense given the interpretation that NULL means "unknown".

Admittedly, this is explained over in the coverage of boolean logic
operators [1] and not with LIKE specifically, but we're not going to
repeat it for every single operator in the system.

            regards, tom lane

[1] https://www.postgresql.org/docs/current/functions-logical.html



pgsql-bugs by date:

Previous
From: Judith Meyer
Date:
Subject: Bug / Unexpected behaviour of NOT LIKE
Next
From: "David G. Johnston"
Date:
Subject: Re: Bug / Unexpected behaviour of NOT LIKE