Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1efW-0003OC-6Z for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Dec 2014 17:15:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y1efU-0002Pm-7i for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Dec 2014 17:15:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y1ef6-00020U-UJ for pgsql-bugs@postgresql.org; Thu, 18 Dec 2014 17:14:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y1eez-0006D9-NG for pgsql-bugs@postgresql.org; Thu, 18 Dec 2014 17:14:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id sBIHEgAq017993; Thu, 18 Dec 2014 12:14:42 -0500 From: Tom Lane To: David G Johnston cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12273: CASE Expression BUG In-reply-to: <1418921627518-5831325.post@n5.nabble.com> References: <20141218144436.1237.96696@wrigleys.postgresql.org> <16630.1418918898@sss.pgh.pa.us> <1418921627518-5831325.post@n5.nabble.com> Comments: In-reply-to David G Johnston message dated "Thu, 18 Dec 2014 09:53:47 -0700" Date: Thu, 18 Dec 2014 12:14:42 -0500 Message-ID: <17992.1418922882@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org David G Johnston writes: > Tom Lane-2 wrote >> We're unlikely to change this, because it would cripple optimization >> attempts. The fact that const-simplification doesn't happen in the other >> way you wrote the function is not more-correct behavior, it's just an >> implementation artifact that you shouldn't rely on. What you need to do >> is code this as an if-then-else sequence, not CASE, so that you don't >> attempt to evaluate any expressions with undefined constant >> subexpressions. > Note that this is documented here: > http://www.postgresql.org/docs/9.4/interactive/functions-conditional.html#FUNCTIONS-CASE > Specifically, the "Note" at the end of 9.17.1 Hmm ... I'd just been looking at 4.2.14: http://www.postgresql.org/docs/9.4/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL and thinking that maybe it should mention this. Perhaps we ought to relocate the text about constant subexpressions into 4.2.14 (and add an example), and then link there from 9.17.1. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs