From: Vik Fearing <vik@postgresfriends.org>
To: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Wrong result with constant quals
Date: Fri, 4 Nov 2022 00:19:16 +0100
Message-ID: <f895925a-f2da-5651-af71-21cd8238b9f5@postgresfriends.org> (raw)
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 <group by clause>, 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 <having clause> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: vik@postgresfriends.org
Subject: Re: Wrong result with constant quals
In-Reply-To: <f895925a-f2da-5651-af71-21cd8238b9f5@postgresfriends.org>
References: <f895925a-f2da-5651-af71-21cd8238b9f5@postgresfriends.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox