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 1oqjUa-0003JG-5n for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Nov 2022 23:19:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oqjUY-0001nq-Bl for pgsql-bugs@arkaria.postgresql.org; Thu, 03 Nov 2022 23:19:22 +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 1oqjUY-0001ng-3B for pgsql-bugs@lists.postgresql.org; Thu, 03 Nov 2022 23:19:22 +0000 Received: from relay11.mail.gandi.net ([2001:4b98:dc4:8::231]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqjUV-0003Ma-EV for pgsql-bugs@postgresql.org; Thu, 03 Nov 2022 23:19:21 +0000 Received: (Authenticated sender: vik@postgresfriends.org) by mail.gandi.net (Postfix) with ESMTPSA id 1AB83100002 for ; Thu, 3 Nov 2022 23:19:16 +0000 (UTC) Message-ID: Date: Fri, 4 Nov 2022 00:19:16 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 From: Vik Fearing Subject: Wrong result with constant quals Content-Language: en-US To: pgsql-bugs Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following query returns a wrong result, in my opinion. postgres=# select 1 where false having true; ?column? ---------- 1 (1 row) The correct result should be zero rows. According to the General Rules of 7.13 , the lack of a GROUP BY clause means the result of the WHERE clause is the sole group. Because of the WHERE FALSE, we should have either a single group with no rows, or no groups, depending on how you look at it. The General Rules of 7.14 dictate that all groups where the HAVING clause evaluates to TRUE are to be output. That will always be the case for this query, so regardless of if we have no groups or one group with no rows, the result should be empty. I cannot find any justification anywhere for why this query should emit any values at all. Hat tip to Lukas Eder: https://twitter.com/lukaseder/status/1588150810466205697 -- Vik Fearing