From: Vik Fearing <vik@postgresfriends.org>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Subject: Re: Wrong result with constant quals
Date: Fri, 4 Nov 2022 00:56:56 +0100
Message-ID: <309137b4-9b48-5952-c6e1-0fa7007d0419@postgresfriends.org> (raw)
In-Reply-To: <2193245.1667518580@sss.pgh.pa.us>
References: <f895925a-f2da-5651-af71-21cd8238b9f5@postgresfriends.org>
<2193245.1667518580@sss.pgh.pa.us>
On 11/4/22 00:36, Tom Lane wrote:
> Vik Fearing <vik@postgresfriends.org> writes:
>> 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.
>
> No, I don't think so. The presence of HAVING without GROUP BY makes
> this act like a query with an aggregate function and no GROUP BY: you
> get a single grouped row, regardless of what the input is. There's a
> reasonably clear specification of that in SQL92 7.8 <having clause>:
SQL92? wut?
> 1) Let T be the result of the preceding <from clause>, <where
> clause>, or <group by clause>. If that clause is not a <group
> by clause>, then T consists of a single group and does not have
> a grouping column.
>
> "A single group" is not "no groups".
>
> Later SQL versions define this by reference to "GROUP BY ()", but
> I think the effect is the same.
I allowed for this by saying it could be a single group with no rows if
you preferred to look at it that way.
This does not explain why the WHERE FALSE is being ignored and producing
rows.
--
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: vik@postgresfriends.org, tgl@sss.pgh.pa.us
Subject: Re: Wrong result with constant quals
In-Reply-To: <309137b4-9b48-5952-c6e1-0fa7007d0419@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