Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fd0Cy-0000LA-GZ for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Jul 2018 21:30:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fd0Cv-0004dO-S4 for pgsql-hackers@arkaria.postgresql.org; Tue, 10 Jul 2018 21:30:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fd0Cv-0004d5-Kn for pgsql-hackers@lists.postgresql.org; Tue, 10 Jul 2018 21:30:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fd0Co-0001SP-8C for pgsql-hackers@lists.postgresql.org; Tue, 10 Jul 2018 21:30:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w6ALTpNN031799; Tue, 10 Jul 2018 17:29:51 -0400 From: Tom Lane To: Peter Eisentraut cc: Nikita Glukhov , Alexander Korotkov , Aleksander Alekseev , PostgreSQL Hackers , Anthony Bykov Subject: Re: Jsonb transform for pl/python In-reply-to: <786ad675-29c5-5acb-9d87-c3609689bf7d@2ndquadrant.com> References: <20171025145100.3a19933f@anthony-24-g082ur> <20180112140425.41174bd3@anthony-24-g082ur> <151577178706.20515.9599911730425998398.pgcf@coridan.postgresql.org> <84a3eaf4-32f6-d2dd-7139-e9c5dd3fec2d@2ndquadrant.com> <6001af16-b242-2527-bc7e-84b8a959163b@postgrespro.ru> <16593cd6-4200-e2ab-8d2e-58b456986d69@postgrespro.ru> <786ad675-29c5-5acb-9d87-c3609689bf7d@2ndquadrant.com> Comments: In-reply-to Peter Eisentraut message dated "Wed, 27 Jun 2018 18:58:19 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <31797.1531258190.1@sss.pgh.pa.us> Date: Tue, 10 Jul 2018 17:29:50 -0400 Message-ID: <31798.1531258190@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Eisentraut 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