Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fDuqh-0007JB-G9 for pgsql-hackers@arkaria.postgresql.org; Wed, 02 May 2018 16:43:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fDuqg-0002a3-BO for pgsql-hackers@arkaria.postgresql.org; Wed, 02 May 2018 16:43:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fDupG-00058M-UM for pgsql-hackers@lists.postgresql.org; Wed, 02 May 2018 16:41:55 +0000 Received: from ping.uio.no ([2001:700:100:570::196]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fDupD-0000Rj-Ft for pgsql-hackers@lists.postgresql.org; Wed, 02 May 2018 16:41:53 +0000 Received: from [2001:700:100:570::211] (helo=dalvik.ping.uio.no ident=Debian-exim) by ping.uio.no with esmtp (Exim 4.72 #1 (Debian)) id 1fDup1-0007g1-3V; Wed, 02 May 2018 18:41:41 +0200 Received: from ilmari by dalvik.ping.uio.no with local (Exim 4.84_2) (envelope-from ) id 1fDup0-0000Df-Sh; Wed, 02 May 2018 18:41:38 +0200 From: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) To: Peter Eisentraut Cc: Tom Lane , Pavel Stehule , Nikita Glukhov , PostgreSQL Hackers Subject: Re: Transform for pl/perl References: <20171127132439.23dc26ef@anthony-24-g082ur> <20171201184921.27he6vbp62yegpvm@alvherre.pgsql> <20171207125455.39067aa7@anthony-24-g082ur> <20171207125602.5326f103@anthony-24-g082ur> <20180112114739.6a9f0d4c@anthony-24-g082ur> <20180131103621.GA19345@zakirov.localdomain> <20180215125313.290468ae@anthony-24-g082ur> <20180312110821.29c80420@anthony-24-g082ur> <505345c5-0159-077d-f64e-60afb01e5fbe@postgrespro.ru> <26a0840a-6b09-44fc-9e4e-8200c1887882@2ndquadrant.com> <15075.1523287460@sss.pgh.pa.us> Mail-Copies-To: nobody Date: Wed, 02 May 2018 17:41:38 +0100 In-Reply-To: (Peter Eisentraut's message of "Mon, 30 Apr 2018 13:27:31 -0400") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Exiscan-Spam-Score: -3.7 (---) X-Exiscan-Spam-Report: SpamAssassin 3.3.1 (2010-03-16) on pike.ping.uio.no Score Rule * -5.0 PING_UIO_MAIL_IS_INTERNAL Message has never been outside * 129.240.0.0/16 or 193.157.115.0/24 * 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Peter Eisentraut writes: > These two items are now outstanding: > > On 4/10/18 07:33, Dagfinn Ilmari Mannsåker wrote: >> 2) jsonb scalar values are passed to the plperl function wrapped in not >> one, but _two_ layers of references > > I don't understand this one, or why it's a problem, or what to do about it. It means that if you call a jsonb-transforming pl/perl function like select somefunc(jsonb '42'); it receives not the scalar 42, but reference to a reference to the scalar (**int instead of an int, in C terms). This is not caught by the current round-trip tests because the output transform automatically dereferences any number of references on the way out again. The fix is to reshuffle the newRV() calls in Jsonb_to_SV() and jsonb_to_plperl(). I am working on a patch (and improved tests) for this, but have not have had time to finish it yet. I hope be able to in the next week or so. >> 3) jsonb numeric values are passed as perl's NV (floating point) type, >> losing precision if they're integers that would fit in an IV or UV. > > This seems fixable, but perhaps we need to think through whether this > will result in other strange behaviors. Nubers > 2⁵³ are not "interoperable" in the sense of the JSON spec, because JavaScript only has doubles, but it seems desirable to preserve whatever precision one reasonably can, and I can't think of any downsides. We already support the full numeric range when processing JSONB in SQL, it's just in the PL/Perl transform (and possibly PL/Python, I didn't look) we're losing precision. Perl can also be configured to use long double or __float128 (via libquadmath) for its NV type, but I think preserving 64bit integers when building against a Perl with a 64bit integer type would be sufficient. - ilmari -- "The surreality of the universe tends towards a maximum" -- Skud's Law "Never formulate a law or axiom that you're not prepared to live with the consequences of." -- Skud's Meta-Law