Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYAAA-0004hr-7p for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Oct 2021 16:53:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mYAA8-0002WP-D1 for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Oct 2021 16:53:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYAA8-0002WH-6O for pgsql-bugs@lists.postgresql.org; Wed, 06 Oct 2021 16:53:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mYAA4-0008LV-Ju for pgsql-bugs@lists.postgresql.org; Wed, 06 Oct 2021 16:52:58 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 196Gqsb24148676; Wed, 6 Oct 2021 12:52:54 -0400 From: Tom Lane To: Judith Meyer cc: pgsql-bugs@lists.postgresql.org Subject: Re: Bug / Unexpected behaviour of NOT LIKE In-reply-to: References: Comments: In-reply-to Judith Meyer message dated "Wed, 06 Oct 2021 17:55:20 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4148674.1633539174.1@sss.pgh.pa.us> Date: Wed, 06 Oct 2021 12:52:54 -0400 Message-ID: <4148675.1633539174@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Judith Meyer 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