From: | Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: improve type conversion of SPI_processed in Python |
Date: | 2018-01-12 15:49:53 |
Message-ID: | 0a02203c-e157-55b2-464e-6087066a1849@2ndquadrant.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 1/9/18 15:54, Tom Lane wrote:
> Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com> writes:
>> Here is a patch to improves how PL/Python deals with very large values
>> of SPI_processed. The previous code converts anything that does not fit
>> into a C long into a Python float. But Python long has unlimited
>> precision, so we should be using that instead. And in Python 3, int and
>> long as the same, so there is no need to deal with any variations anymore.
>
> I took a quick look at this. +1 for returning Python long all the time,
> but I wonder why the Python version dependency.
To keep returning an int in Python 2 in the cases it fits. Maybe that's
overkill.
> Our existing function
> PLyLong_FromInt64() believes that PyLong_FromLongLong is unconditionally
> available.
Interesting. I had coded this to account for the possibility that long
long does not exist on a 64-bit platform, but that situation probably
died with the first Alpha or something.
> I'd be inclined to code PLyObject_FromUint64() as an exact
> analog of PLyLong_FromInt64(), ie
>
> /* on 32 bit platforms "unsigned long" may be too small */
> if (sizeof(uint64) > sizeof(unsigned long))
> return PyLong_FromUnsignedLongLong(DatumGetUInt64(d));
> else
> return PyLong_FromUnsignedLong(DatumGetUInt64(d));
>
> and let Python worry about how to optimize the conversion.
Would that even be necessary? Why not use the LongLong variant all the
time then?
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
From | Date | Subject | |
---|---|---|---|
Next Message | Teodor Sigaev | 2018-01-12 15:51:48 | Re: [HACKERS] PoC: custom signal handler for extensions |
Previous Message | Tom Lane | 2018-01-12 15:45:54 | Re: Changing WAL Header to reduce contention during ReserveXLogInsertLocation() |