Wrong result with constant quals

From: Vik Fearing <vik(at)postgresfriends(dot)org>
To: pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Wrong result with constant quals
Date: 2022-11-03 23:19:16
Message-ID: f895925a-f2da-5651-af71-21cd8238b9f5@postgresfriends.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2022-11-03 23:36:20 Re: Wrong result with constant quals
Previous Message David G. Johnston 2022-11-03 20:12:35 Re: BUG #17676: Text comparison appears to be wrong