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: plpgsql: numeric assignment to an integer variable errors out
Date: 2008-12-11 12:35:45
Message-ID: a301bfd90812110435l399acc41n6a74caa51f8ab229@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The following plpgsql function errors out with cvs head:

CREATE function test_assign() returns void
AS
$$ declare x int;
BEGIN
x := 9E3/2;
END
$$ 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.

Regards,
Nikhils
--
http://www.enterprisedb.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2008-12-11 12:42:15 Re: COCOMO & Indians
Previous Message Dmitry Turin 2008-12-11 12:31:22 Re: COCOMO & Indians