pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jaksits.tibor@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #12273: CASE Expression BUG
Date: Thu, 18 Dec 2014 11:08:18 -0500
Message-ID: <16630.1418918898@sss.pgh.pa.us> (raw)
In-Reply-To: <20141218144436.1237.96696@wrigleys.postgresql.org>
References: <20141218144436.1237.96696@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (10+ messages)  latest in thread

Message-ID: <16630.1418918898@sss.pgh.pa.us>
Permalink:  ../16630.1418918898@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/16630.1418918898@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jaksits.tibor@gmail.com
  Subject: Re: BUG #12273: CASE Expression BUG
  In-Reply-To: <16630.1418918898@sss.pgh.pa.us>
  References: <20141218144436.1237.96696@wrigleys.postgresql.org> <16630.1418918898@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox