Skip site navigation (1) Skip section navigation (2)

Re: plpgsql: numeric assignment to an integer variable errors out

From: "Nikhil Sontakke" <nikhil(dot)sontakke(at)enterprisedb(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: plpgsql: numeric assignment to an integer variable errors out
Date: 2008-12-29 15:02:13
Message-ID: (view raw or whole thread)
Lists: pgsql-hackers

<nikhil(dot)sontakke(at)enterprisedb(dot)com> wrote:

> The following plpgsql function errors out with cvs head:
> CREATE function test_assign() returns void
> AS
> $$ declare x int;
> x := 9E3/2;
> $$ LANGUAGE 'plpgsql';
> postgres=# select test_assign();
> ERROR:  invalid input syntax for integer: "4500.0000000000000000"
> CONTEXT:  PL/pgSQL function "test_assign" line 3 at assignment
> We do have an existing cast from numeric to type integer. But here
> basically we convert the value to string in exec_cast_value before calling
> int4in. And then use of strtol in pg_atoi leads to this complaint. Guess
> converting the value to string is not always a good strategy.

PFA, patch which uses find_coercion_pathway to find a direct
COERCION_PATH_FUNC function and uses that if it is available. Or is there a
better approach? Seems to handle the above issue with this patch.


Attachment: plpgsql_numeric_bug.patch
Description: text/x-diff (2.0 KB)

In response to


pgsql-hackers by date

Next:From: Kevin GrittnerDate: 2008-12-29 15:16:42
Subject: Re: incoherent view of serializable transactions
Previous:From: Peter EisentrautDate: 2008-12-29 14:48:29
Subject: Re: Several tags around PostgreSQL 7.1 broken

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group