Re: [PATCH] Fix conversion for Decimal arguments in plpython functions - Mailing list pgsql-hackers

From Szymon Guz
Subject Re: [PATCH] Fix conversion for Decimal arguments in plpython functions
Date
Msg-id CAFjNrYt6o61d-TqoL=yFfHrVSy6o2Tqq-joCsn54CZPsYYPZBg@mail.gmail.com
Whole thread Raw
In response to Re: [PATCH] Fix conversion for Decimal arguments in plpython functions  (Szymon Guz <mabewlun@gmail.com>)
Responses Re: [PATCH] Fix conversion for Decimal arguments in plpython functions
List pgsql-hackers
On 26 June 2013 22:08, Szymon Guz <mabewlun@gmail.com> wrote:
On 26 June 2013 21:59, Peter Eisentraut <peter_e@gmx.net> wrote:
On 6/26/13 7:03 AM, Szymon Guz wrote:
> I've checked the patch, everything looks great.
> I've attached it to this email with changed name, just for consistent
> naming in commitfest app.

Could the setup of the decimal.Decimal constructor be moved into
PLyDecimal_FromNumeric() and kept in a static pointer?  I'd rather not
clutter up the main initialization routine.



Attached patch has all changes against trunk code.

There is added a function for conversion from Postgres numeric to Python Decimal. The Decimal type is taken from cdecimal.Decimal, if it is available. It is an external library, quite fast, but may be not available. If it is not available, then decimal.Decimal will be used. It is in standard Python library, however it is rather slow.

The initialization is done in the conversion function, the pointer to a proper Decimal constructor is stored as static variable inside the function and is lazy initialized.

The documentation is updated.

Tests for python 2 and 3 have been added. They work only with standard decimal.Decimal, as the type is printed in the *.out files. I think there is nothing we can do with that now.


regards,
Szymon
Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: MD5 aggregate
Next
From: Selena Deckelmann
Date:
Subject: Re: Kudos for Reviewers -- straw poll