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 1fQz5z-0001OP-C1 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Jun 2018 17:53:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fQz5v-0007kZ-HO for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Jun 2018 17:53:07 +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 1fQz5v-0007kQ-6x for pgsql-hackers@lists.postgresql.org; Thu, 07 Jun 2018 17:53:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fQz5s-0001Zb-43 for pgsql-hackers@lists.postgresql.org; Thu, 07 Jun 2018 17:53:05 +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 w57Hqngw028337; Thu, 7 Jun 2018 13:52:49 -0400 From: Tom Lane To: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) cc: Peter Eisentraut , Alvaro Herrera , Pavel Stehule , Nikita Glukhov , PostgreSQL Hackers Subject: Re: Transform for pl/perl In-reply-to: References: <20180606161453.tvp4ltavlcvejmmz@alvherre.pgsql> Comments: In-reply-to ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) message dated "Thu, 07 Jun 2018 14:54:10 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28335.1528393969.1@sss.pgh.pa.us> Date: Thu, 07 Jun 2018 13:52:49 -0400 Message-ID: <28336.1528393969@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=) writes: > Peter Eisentraut writes: >> The way I understand it, it's only how things are passed around >> internally. Nothing is noticeable externally, and so there is no >> backward compatibility issue. >> >> At least that's how I understand it. So far this is only a claim by one >> person. I haven't seen anything conclusive about whether there is an >> actual issue. > It's not just how things are passed internally, but how they are passed > to pl/perl functions with a jsonb transform: JSON scalar values at the > top level (strings, numbers, booleans, null) get passed as a reference > to a reference to the value, e.g. \\42 instead of 42. The reason the > current tests don't pick this up is that they don't check the value > inside the pl/perl functions, only that they roundtrip back to jsonb, > and the plperl to jsonb transform recursively dereferences references. Yeah, the reason this is important is that it affects what the plperl function body sees. > Another side effect of the recursive dereferencing is that returning > undef from the perl function returns an SQL NULL while returning a > reference to undef (\undef) returns a jsonb null. Hm, I think you're blaming the wrong moving part there. The way the transform logic is set up (e.g., in plperl_sv_to_datum()), it's impossible for a transform function to return a SQL null; the decision by plperl_sv_to_datum as to whether or not the output will be a SQL null is final. (Perhaps that was a mistake, but changing the transform function API seems like a rather Big Deal.) So if we think that \undef ought to produce a SQL null, the thing to do is move the dereferencing loop to the beginning of plperl_sv_to_datum, and then \undef would produce NULL whether this transform is installed or not. I don't have a well-informed opinion on whether that's a good idea, but I tend to the view that it is. Right now the case produces an error, and not even a very sane one: regression=# create function foo() returns int language plperlu regression-# as '\undef'; CREATE FUNCTION regression=# select foo(); ERROR: PL/Perl function must return reference to hash or array CONTEXT: PL/Perl function "foo" so there's not really a compatibility break if we redefine it. regards, tom lane