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

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Nikhil Sontakke" <nikhil(dot)sontakke(at)enterprisedb(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: plpgsql: numeric assignment to an integer variable errors out
Date: 2008-12-29 17:10:17
Message-ID: 162867790812290910y3d0d5420ube7b5db8d6b53cfc@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2008/12/29 Nikhil Sontakke <nikhil(dot)sontakke(at)enterprisedb(dot)com>:
> Hi,
>
> <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;
>> 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.
>
> 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.

+1

I thing, so some values should by cached, current patch could by slow.

Regards
Pavel Stehule

>
> Regards,
> Nikhils
> --
> http://www.enterprisedb.com
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2008-12-29 17:19:55 Re: TODO items for window functions
Previous Message Tom Lane 2008-12-29 16:59:51 Re: TODO items for window functions