Re: Weird behaviour of ROLLUP/GROUPING

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Guillaume Lelarge <guillaume(at)lelarge(dot)info>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Weird behaviour of ROLLUP/GROUPING
Date: 2019-01-16 13:15:01
Message-ID: CAFj8pRAqsdEKFg9bHp2mY02+1PJx=KN_EWy9HFBbD92xGu3oAg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

st 16. 1. 2019 v 13:51 odesílatel Guillaume Lelarge <guillaume(at)lelarge(dot)info>
napsal:

> Hi,
>
> One of my customers found something quite weird on his 9.6 cluster. Here
> is a quick demo showing the issue:
>
> -- quick demo table
> CREATE TABLE t1 (a integer, b timestamp, c integer);
>
> -- a working query
> SELECT
> CASE grouping(a) WHEN 1 THEN 'some text' ELSE a::text END AS new_a,
> CASE WHEN grouping(to_char(b, 'MMYYYY')) = 1
> THEN 'some date'
> ELSE to_char(b, 'MMYYYY') END AS new_b,
> sum(c)
> FROM t1
> GROUP BY ROLLUP(a, to_char(b,'MMYYYY'));
>
> -- the non-working query
> SELECT
> CASE grouping(a) WHEN 1 THEN 'some text' ELSE a::text END AS new_a,
> CASE grouping(to_char(b, 'MMYYYY'))
> WHEN 1 THEN 'some date'
> ELSE to_char(b, 'MMYYYY') END AS new_b,
> sum(c)
> FROM t1
> GROUP BY ROLLUP(a, to_char(b,'MMYYYY'));
> ERROR: arguments to GROUPING must be grouping expressions of the
> associated query level
> LINE 3: CASE grouping(to_char(b, 'MMYYYY')) WHEN 1 THEN 'some date' ...
> ^
>
> AFAICT, both queries should behave the same, though their actual
> behaviours are quite opposite. Working fine for the first, erroring out on
> the second.
>
> Does anyone has any idea what's going on here?
>
> BTW, it shows the same issue on 11.1 (actually HEAD on REL_11_STABLE).
>

looks like PostgreSQL bug - it cannot to work with subqueries correctly

Pavel

>
> Thanks.
>
> Regards.
>
>
> --
> Guillaume.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message aaaaaa 2019-01-16 14:36:50 problem in regard to hot standby
Previous Message Guillaume Lelarge 2019-01-16 12:51:27 Weird behaviour of ROLLUP/GROUPING