Re: BUG #13918: Simple query with Having clause returns incorrect results

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "tarasbob(at)gmail(dot)com" <tarasbob(at)gmail(dot)com>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #13918: Simple query with Having clause returns incorrect results
Date: 2016-02-09 04:17:52
Message-ID: 19844.1454991472@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Thursday, February 4, 2016, <tarasbob(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2016-02-09 04:46:38 Re: BUG #13919: Cast error when table is empty.
Previous Message Michael Paquier 2016-02-09 03:29:22 Re: BUG #13928: Initdb.bat will not install if path has a space.