Re: Jsonb transform for pl/python
| От | Tom Lane |
|---|---|
| Тема | Re: Jsonb transform for pl/python |
| Дата | |
| Msg-id | 31798.1531258190@sss.pgh.pa.us обсуждение |
| Ответ на | Re: Jsonb transform for pl/python (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>) |
| Ответы |
Re: Jsonb transform for pl/python
|
| Список | pgsql-hackers |
Peter Eisentraut <peter.eisentraut@2ndquadrant.com> writes:
> On 6/23/18 01:44, Nikita Glukhov wrote:
>> We are simply trying first to convert numeric to int64 if is does not have
>> digits after the decimal point, and then construct Python Int instead of
>> Decimal. Standard Python json.loads() does the same for exact integers.
> We just had a very similar but not identical discussion in the thread
> about the PL/Perl transforms, where we rejected the proposal. Other
> comments on this one?
I can sympathize with the speed concern, but the proposed patch produces
a functional change (ie, you get a different kind of Python object, with
different behaviors, in some cases). That seems to me to be a good reason
to reject it. The fact that it makes the behavior vary depending on the
local width of "long" is also a problem, although I think that could be
fixed.
More generally, I'd be happier with a patch that sped things up for
non-integers too. I don't know whether Python exposes enough internals
of type Decimal to make that practical, though. One idea for doing it at
arm's length is to compute the Decimal value using numeric-digit-at-a-time
arithmetic, roughly
x := 0;
foreach(digit, numeric)
x.fma(10000, digit);
x.scaleb(appropriate-exponent);
In principle that's probably faster than string conversion, but not
sure by how much.
regards, tom lane
В списке pgsql-hackers по дате отправления: