On Wed, Mar 5, 2025 at 11:02 AM Richard Guo <guofengli...@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


Reply via email to