Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjoFL-00033K-H3 for pgsql-general@arkaria.postgresql.org; Wed, 16 Jan 2019 16:40:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gjoFK-0001jc-0v for pgsql-general@arkaria.postgresql.org; Wed, 16 Jan 2019 16:40:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjoFJ-0001gF-N9 for pgsql-general@lists.postgresql.org; Wed, 16 Jan 2019 16:40:53 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjoFH-0001B2-Pv for pgsql-general@postgresql.org; Wed, 16 Jan 2019 16:40:53 +0000 Received: from [192.168.127.1] (port=47985 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1gjoFG-0006bx-0q; Wed, 16 Jan 2019 16:40:50 +0000 Received: from [127.0.0.1] (port=13015 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gjoFF-000At5-A0; Wed, 16 Jan 2019 16:40:49 +0000 From: Andrew Gierth To: Guillaume Lelarge Cc: PostgreSQL General Subject: Re: Weird behaviour of ROLLUP/GROUPING In-Reply-To: <874la8lhvp.fsf@news-spur.riddles.org.uk> (Andrew Gierth's message of "Wed, 16 Jan 2019 15:55:21 +0000") Message-ID: <87r2dck1dn.fsf@news-spur.riddles.org.uk> References: <874la8lhvp.fsf@news-spur.riddles.org.uk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Wed, 16 Jan 2019 16:40:49 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Andrew" == Andrew Gierth writes: >>>>> "Guillaume" == Guillaume Lelarge writes: Guillaume> CASE grouping(to_char(b, 'MMYYYY')) Guillaume> ERROR: arguments to GROUPING must be grouping expressions of the Guillaume> associated query level Guillaume> LINE 3: CASE grouping(to_char(b, 'MMYYYY')) WHEN 1 THEN 'some date' ... Guillaume> AFAICT, both queries should behave the same, though their Guillaume> actual behaviours are quite opposite. Working fine for the Guillaume> first, erroring out on the second. Guillaume> Does anyone has any idea what's going on here? Andrew> Not yet. But I will find out, since it seems to be a bug. It is definitely a bug, to do with assignment of collations. It specifically happens when you use GROUPING which contains any subexpression of a collatable type, inside a CASE expr WHEN clause, since that assigns collations to the expression much earlier in parsing than the rest of the query, so the code that validates GROUPING ends up trying to compare an expression which has had collations assigned to it to one which has not, and so it thinks they differ. I will see about fixing this, somehow. -- Andrew (irc:RhodiumToad)