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

From Steve Singer
Subject Re: [PATCH] Fix conversion for Decimal arguments in plpython functions
Date
Msg-id BLU0-SMTP182DAC71F85B2679752472DC750@phx.gbl
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 06/26/2013 04:47 PM, Szymon Guz wrote:
>
>
>
>
> 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.
>

I've tested this version with python 2.7 with and without cdecimal and
also with 3.3 that has the faster decimal performance. It seems fine.

The v5 version of the patch makes only white-space changes to
plpy_main.c you should excluded that from the patch if your making a new
version (I have done this in the v6 version I'm attaching)


> 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.
>
>

I think we should make  test_type_conversion_numeric to do something
that generates the same output in both cases.  ie
py.info(str(x)).  I downside of having the test fail on installs with
cdecimal installed is much greater than any benefit we get by ensuring
that the type is really decimal.
I've attached a v6 version of the patch that does this, do you agree
with my thinking?




Steve






> regards,
> Szymon
>
>


Attachment

pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: FILTER for aggregates [was Re: Department of Redundancy Department: makeNode(FuncCall) division]
Next
From: Tom Lane
Date:
Subject: Re: pg_filedump 9.3: checksums (and a few other fixes)