Re: Wrong results with subquery pullup and grouping sets

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Pg Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Wrong results with subquery pullup and grouping sets
Date: 2025-03-05 02:22:37
Message-ID: CAMbWs49jahdToB3C4mfoskWcShqqT9Yn-uf-X+GKyZUcP2u7fQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 5, 2025 at 11:02 AM Richard Guo <guofenglinux(at)gmail(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Alexander Korotkov 2025-03-05 02:27:20 Re: Considering fractional paths in Append node
Previous Message Michael Paquier 2025-03-05 02:05:48 Add regression test checking combinations of (object,backend_type,context) in pg_stat_io