Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHTSj-0008Bw-O2 for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Oct 2018 12:49:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHTSi-0007rW-5p for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Oct 2018 12:49:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHTSh-0007pU-SR for pgsql-bugs@lists.postgresql.org; Tue, 30 Oct 2018 12:49:36 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHTSd-0007cE-Vj for pgsql-bugs@lists.postgresql.org; Tue, 30 Oct 2018 12:49:34 +0000 Received: from [192.168.127.1] (port=19096 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 1gHTSZ-000D00-Uo; Tue, 30 Oct 2018 12:49:27 +0000 Received: from [127.0.0.1] (port=48559 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1gHTSZ-000NR6-63; Tue, 30 Oct 2018 12:49:27 +0000 From: Andrew Gierth To: Tom Lane Cc: pg@mattyw.net, pgsql-bugs@lists.postgresql.org, Andres Freund Subject: Re: BUG #15471: psql 11 array concatenation in CASE takes on values from the CASE expression when using enum_range In-Reply-To: <8112.1540900775@sss.pgh.pa.us> (Tom Lane's message of "Tue, 30 Oct 2018 07:59:35 -0400") Message-ID: <87efc77gh2.fsf@news-spur.riddles.org.uk> References: <15471-1117f49271989bad@postgresql.org> <8112.1540900775@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 30 Oct 2018 12:49:25 +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: >> Below is an example .sql file that replicates the problem. Put >> simply, when we array concat with enum_range in the result of a CASE >> statement the concatenation takes the expression from the CASE >> statement, not the enum range. Tom> Wow, that's ... bizarre. I'm thinking that we probably did Tom> something silly in the big expression-execution rewrite, but it's Tom> not clear exactly where. Anyway, will look into it if Andres Tom> doesn't beat me to it. I took a look, and what I'm seeing suggests that commit 3decd150a2d might possibly be relevant here (at least to explain why it breaks in 11 but not 10). What's going on in eval_const_expressions_mutator is that context->case_val is set when recursing into the elemexpr in the ArrayCoerceExpr case, so when that sees a CaseTestExpr inside that, it replaces it (incorrectly). -- Andrew (irc:RhodiumToad)