Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y1dcn-0000Mk-Ge for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Dec 2014 16:08:25 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y1dcn-0005Cw-1J for pgsql-bugs@arkaria.postgresql.org; Thu, 18 Dec 2014 16:08:25 +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 1Y1dcm-0005Co-DW for pgsql-bugs@postgresql.org; Thu, 18 Dec 2014 16:08:24 +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 1Y1dcj-0004zi-3G for pgsql-bugs@postgresql.org; Thu, 18 Dec 2014 16:08:23 +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 sBIG8Iua016631; Thu, 18 Dec 2014 11:08:18 -0500 From: Tom Lane To: jaksits.tibor@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #12273: CASE Expression BUG In-reply-to: <20141218144436.1237.96696@wrigleys.postgresql.org> References: <20141218144436.1237.96696@wrigleys.postgresql.org> Comments: In-reply-to jaksits.tibor@gmail.com message dated "Thu, 18 Dec 2014 14:44:36 +0000" Date: Thu, 18 Dec 2014 11:08:18 -0500 Message-ID: <16630.1418918898@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 jaksits.tibor@gmail.com writes: > CREATE OR REPLACE FUNCTION __is_numeric_test_does_not_work(a_text_param > text) > RETURNS double precision AS > $BODY$DECLARE > ret double precision; > BEGIN > SELECT __is_numeric_test > INTO ret > FROM __is_numeric_test((CASE WHEN is_numeric(a_text_param) THEN > a_text_param::double precision ELSE 0.0::double precision END)); > RETURN ret; > END;$BODY$ > LANGUAGE plpgsql VOLATILE; > But the query "SELECT * FROM __is_numeric_test_does_not_work('')" I get an > error message: > invalid input syntax for type double precision: "" You didn't show us what is_numeric() is, so it's impossible to reproduce this example, but I imagine what is happening is that the value of a_text_param is being substituted into the SELECT as a text constant, and then constant-folding leads to attempting to simplify a_text_param::double precision immediately. 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. 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