Wrong result with constant quals - Mailing list pgsql-bugs

From Vik Fearing
Subject Wrong result with constant quals
Date
Msg-id f895925a-f2da-5651-af71-21cd8238b9f5@postgresfriends.org
Whole thread Raw
Responses Re: Wrong result with constant quals  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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



pgsql-bugs by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: BUG #17676: Text comparison appears to be wrong
Next
From: Tom Lane
Date:
Subject: Re: Wrong result with constant quals