Re: Bug / Unexpected behaviour of NOT LIKE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Judith Meyer <yutian(dot)mei(at)gmail(dot)com>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Bug / Unexpected behaviour of NOT LIKE
Date: 2021-10-06 16:52:54
Message-ID: 4148675.1633539174@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Judith Meyer <yutian(dot)mei(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Geoghegan 2021-10-06 17:16:09 Re: BUG #17212: pg_amcheck fails on checking temporary relations
Previous Message Mark Dilger 2021-10-06 16:25:49 Re: BUG #17212: pg_amcheck fails on checking temporary relations