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 1fRKQA-0001lj-DQ for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Jun 2018 16:39:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fRKQ8-0001vU-Vc for pgsql-hackers@arkaria.postgresql.org; Fri, 08 Jun 2018 16:39:24 +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 1fRKQ8-0001vC-KV for pgsql-hackers@lists.postgresql.org; Fri, 08 Jun 2018 16:39:24 +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 1fRKQ5-0007Ms-Ro for pgsql-hackers@lists.postgresql.org; Fri, 08 Jun 2018 16:39:23 +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 w58Gd7R9027214; Fri, 8 Jun 2018 12:39:07 -0400 From: Tom Lane To: Peter Eisentraut cc: ilmari@ilmari.org (Dagfinn Ilmari =?utf-8?Q?Manns=C3=A5ker?=), Alvaro Herrera , Pavel Stehule , Nikita Glukhov , PostgreSQL Hackers Subject: Re: Transform for pl/perl In-reply-to: <28336.1528393969@sss.pgh.pa.us> References: <20180606161453.tvp4ltavlcvejmmz@alvherre.pgsql> <28336.1528393969@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 07 Jun 2018 13:52:49 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <27212.1528475947.1@sss.pgh.pa.us> Date: Fri, 08 Jun 2018 12:39:07 -0400 Message-ID: <27213.1528475947@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > ... 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. After further thought, the only argument I can think of for preserving this existing behavior is if we wanted to reserve returning a reference- to-scalar for some future purpose, ie make it do something different from returning the referenced value. I can't think of any likely use of that kind, but maybe I'm just insufficiently creative today. However, if one makes that argument, then it is clearly a bad idea for jsonb_plperl to be forcibly dereferencing such references: once we do make a change of that sort, jsonb_plperl will be out of step with the behavior for every other datatype, or else we will need to make a subtle compatibility break to align it with whatever the new behavior is. So it seems that whichever way you stand on that, it's wrong to have that dereference loop in SV_to_JsonbValue(). I'm forced to the conclusion that that's just a hack to band-aid over a bug in the transform's other direction. Now, if we did decide that auto-dereferencing should be the general rule in perl->SQL conversions, I'd be inclined to leave that loop in place in SV_to_JsonbValue(), because it would be covering the case where jsonb_plperl is recursively disassembling an AV or HV and finds a reference-to-scalar. But we also need a dereference loop in at least one place in plperl.c itself if that's the plan. I'm inclined to think that auto-dereference is indeed a good idea, and am tempted to go make that change to make all this consistent. Comments? regards, tom lane