Re: [PATCH] Fix conversion for Decimal arguments in plpython functions

From: Steve Singer <steve(at)ssinger(dot)info>
To: Szymon Guz <mabewlun(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, Ronan Dunklau <rdunklau(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Fix conversion for Decimal arguments in plpython functions
Date: 2013-06-27 03:21:17
Message-ID: BLU0-SMTP182DAC71F85B2679752472DC750@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: 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 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?


> regards,
> Szymon

Attachment Content-Type Size
plpython_decimal_v6.patch text/x-patch 12.0 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2013-06-27 03:27:28 Re: pg_filedump 9.3: checksums (and a few other fixes)
Previous Message Tom Lane 2013-06-27 03:05:44 Re: FILTER for aggregates [was Re: Department of Redundancy Department: makeNode(FuncCall) division]