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 1f3jMw-0004tb-0z for pgsql-committers@arkaria.postgresql.org; Wed, 04 Apr 2018 14:26:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f3jMu-00039o-TB for pgsql-committers@arkaria.postgresql.org; Wed, 04 Apr 2018 14:26:32 +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 1f3jMu-00039f-KW for pgsql-committers@lists.postgresql.org; Wed, 04 Apr 2018 14:26:32 +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 1f3jMr-0007d4-I3 for pgsql-committers@lists.postgresql.org; Wed, 04 Apr 2018 14:26:31 +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 w34EQNBW030495; Wed, 4 Apr 2018 10:26:23 -0400 From: Tom Lane To: Anthony Bykov cc: Peter Eisentraut , pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Transforms for jsonb to PL/Perl In-reply-to: <20180404161144.37d03301@anthony-24-g082ur> References: <13723.1522768121@sss.pgh.pa.us> <3001.1522769607@sss.pgh.pa.us> <15089.1522791424@sss.pgh.pa.us> <20180404161144.37d03301@anthony-24-g082ur> Comments: In-reply-to Anthony Bykov message dated "Wed, 04 Apr 2018 16:11:44 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30493.1522851983.1@sss.pgh.pa.us> Date: Wed, 04 Apr 2018 10:26:23 -0400 Message-ID: <30494.1522851983@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Anthony Bykov writes: > Tom Lane wrote: >> This results in one change in the module's test results: the example >> that thinks it's returning a regexp match result no longer fails, >> but just returns the scalar result (0). I'm inclined to think that >> this is correct/desirable and the existing behavior is an accidental >> artifact of not coping with Perl's various augmented representations >> of scalar values. > I think that there is a mistake in test: > CREATE FUNCTION testRegexpToJsonb() RETURNS jsonb > LANGUAGE plperl > TRANSFORM FOR TYPE jsonb > AS $$ > return ('1' =~ m(0\t2)); > $$; > =~ is the operator testing a regular expression match. > Hence, testRegexpToJsonb function returns true/false values > (when used in scalar context, the return value > generally indicates the success of the operation). Right, that was my point: this is returning a scalar result that just happens to have been derived from a regexp match. So the output ought to be 1 or 0, and the fact that (on some platforms?) it isn't represents a bug. > I guess the right test will look a little bit different: > CREATE FUNCTION testRegexpToJsonb() RETURNS jsonb > LANGUAGE plperl > TRANSFORM FOR TYPE jsonb > AS $$ > $a = qr//; > return ($a); > $$; This is testing something else. I don't object to adding it, but we should keep the existing test in some form to verify that the bug stays fixed. regards, tom lane