Re: Wrong results with subquery pullup and grouping sets - Mailing list pgsql-hackers

From Richard Guo
Subject Re: Wrong results with subquery pullup and grouping sets
Date
Msg-id CAMbWs49jahdToB3C4mfoskWcShqqT9Yn-uf-X+GKyZUcP2u7fQ@mail.gmail.com
Whole thread Raw
In response to Wrong results with subquery pullup and grouping sets  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers
On Wed, Mar 5, 2025 at 11:02 AM Richard Guo <guofenglinux@gmail.com> wrote:
> create table t (a int);
> insert into t values (1);
>
> # select a, b
>   from (select a, a as b from t) ss
>   group by grouping sets(a, b)
>   having b = 1;
>  a | b
> ---+---
>  1 |
> (1 row)
>
> Note that the having clause filters out the wrong row.

BTW, this issue is not limited to HAVING clause; it can also happen to
targetlist.

# select a, b+1
  from (select a, a as b from t) ss
  group by grouping sets(a, b);
 a | ?column?
---+----------
 1 |        2
   |
(2 rows)

Surely this is wrong.

Thanks
Richard



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Add regression test checking combinations of (object,backend_type,context) in pg_stat_io
Next
From: Alexander Korotkov
Date:
Subject: Re: Considering fractional paths in Append node