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 1gjxkY-000164-2g for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Jan 2019 02:49:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gjxjW-0008VB-Tp for pgsql-hackers@arkaria.postgresql.org; Thu, 17 Jan 2019 02:48:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjxjW-0008V3-Fe for pgsql-hackers@lists.postgresql.org; Thu, 17 Jan 2019 02:48:42 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gjxjO-00016R-L8 for pgsql-hackers@postgresql.org; Thu, 17 Jan 2019 02:48:40 +0000 Received: from [192.168.127.1] (port=29835 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 1gjxjM-0007Ew-6X; Thu, 17 Jan 2019 02:48:32 +0000 Received: from [127.0.0.1] (port=15219 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gjxjL-000Dkb-Hc; Thu, 17 Jan 2019 02:48:31 +0000 From: Andrew Gierth To: Tom Lane Cc: pgsql-hackers@postgresql.org Subject: Re: parseCheckAggregates vs. assign_query_collations In-Reply-To: <16969.1547660970@sss.pgh.pa.us> (Tom Lane's message of "Wed, 16 Jan 2019 12:49:30 -0500") Message-ID: <871s5cj9mn.fsf@news-spur.riddles.org.uk> References: <87muo0k0c7.fsf@news-spur.riddles.org.uk> <16969.1547660970@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Thu, 17 Jan 2019 02:48:31 +0000 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >>>>> "Tom" == Tom Lane writes: >> I'll be looking into this in detail later, but right now, cam anyone >> think of any reason why parseCheckAggregates couldn't be moved to >> after assign_query_collations? Tom> I never particularly liked assign_query_collations, as a matter of Tom> overall system design. I'd prefer to nuke that and instead require Tom> collation assignment to be done per-expression, ie at the end of Tom> transformExpr and similar places. Now that we've seen this Tom> example, it's fairly clear why collation assignment really should Tom> be considered an integral part of expression parsing. Who's to say Tom> there aren't more gotchas of this sort waiting to bite us? Also, Tom> if it were integrated into transformExpr as it should have been to Tom> begin with, we would not have the need for quite so many random Tom> calls to assign_expr_collations, with consequent bugs of omission, Tom> cf 7a28e9aa0. Sure, this might be the right approach going forward. But right now we need a back-patchable fix, and the above sounds a bit too intrusive for that. Turns out the issue can be reproduced without grouping sets too: select case a||'' when '1' then 0 else 1 end from (select (select random()::text) as a) s group by a||''; ERROR: column "s.a" must appear in the GROUP BY clause or be used in an aggregate function select case when a||'' = '1' then 0 else 1 end from (select (select random()::text) as a) s group by a||''; -- works -- Andrew (irc:RhodiumToad)