Re: Bug / Unexpected behaviour of NOT LIKE

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Bug / Unexpected behaviour of NOT LIKE
Дата
Msg-id 4148675.1633539174@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Bug / Unexpected behaviour of NOT LIKE  (Judith Meyer <yutian.mei@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Judith Meyer
Дата:
Сообщение: Bug / Unexpected behaviour of NOT LIKE
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: Bug / Unexpected behaviour of NOT LIKE