Re: BUG #13918: Simple query with Having clause returns incorrect results - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #13918: Simple query with Having clause returns incorrect results
Date
Msg-id 19844.1454991472@sss.pgh.pa.us
Whole thread Raw
In response to Re: BUG #13918: Simple query with Having clause returns incorrect results  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Thursday, February 4, 2016, <tarasbob@gmail.com> wrote:
>> The following query incorrectly returns 1 row instead of 0:
>>
>> SELECT 1
>> FROM some_table
>> WHERE FALSE
>> HAVING TRUE

> So, amazingly (to me), this behavior is documented.

>> The presence of HAVING turns a query into a grouped query even if there is
>> no GROUP BY clause. ... Such a
>> query will emit a single row if the HAVING condition is true, zero rows if
>> it is not true.

Yeah.  This is a pretty weird corner case, but the behavior is required
by SQL spec.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: BUG #13928: Initdb.bat will not install if path has a space.
Next
From: Tom Lane
Date:
Subject: Re: BUG #13919: Cast error when table is empty.