Re: Wrong result with constant quals - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Wrong result with constant quals
Date
Msg-id 2193245.1667518580@sss.pgh.pa.us
Whole thread Raw
In response to Wrong result with constant quals  (Vik Fearing <vik@postgresfriends.org>)
Responses Re: Wrong result with constant quals  (Vik Fearing <vik@postgresfriends.org>)
List pgsql-bugs
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>:

         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.

            regards, tom lane



pgsql-bugs by date:

Previous
From: Vik Fearing
Date:
Subject: Wrong result with constant quals
Next
From: Vik Fearing
Date:
Subject: Re: Wrong result with constant quals