Re: BUG #3686: Incorrect numeric type conversion to long in plpythonu

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Sergi" <sergi(dot)vladykin(at)googlemail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #3686: Incorrect numeric type conversion to long in plpythonu
Date: 2007-10-21 23:15:27
Message-ID: 17901.1193008527@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Sergi" <sergi(dot)vladykin(at)googlemail(dot)com> writes:
> Problem is that numeric type converts to pythons long
> incorrectly. Here is the simple script that shows this.

The reason you're having a problem is that plpython translates PG's
numeric datatype to Python Float type, and thus the precision is
lost before the long() function ever sees it.

We can't fix this by translating to Long instead, since that would lose
fractional digits.

We could consider translating to the Decimal type proposed in PEP 327
http://www.python.org/dev/peps/pep-0327/
however it appears that that's only standard in Python 2.4 and later
which makes it rather a large portability problem. I have no idea
what sort of backwards-compatibility issues such a change would
create, either ...

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Gary Chambers 2007-10-22 03:17:49 Re: BUG #3682: Incomplete database restore
Previous Message Tom Lane 2007-10-21 20:24:05 Re: BUG #3682: Incomplete database restore