Re: pgsql: Transforms for jsonb to PL/Perl - Mailing list pgsql-committers

From Tom Lane
Subject Re: pgsql: Transforms for jsonb to PL/Perl
Date
Msg-id 30494.1522851983@sss.pgh.pa.us
Whole thread Raw
In response to Re: pgsql: Transforms for jsonb to PL/Perl  (Anthony Bykov <a.bykov@postgrespro.ru>)
Responses Re: pgsql: Transforms for jsonb to PL/Perl  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-committers
Anthony Bykov <a.bykov@postgrespro.ru> writes:
> Tom Lane <tgl@sss.pgh.pa.us> 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


pgsql-committers by date:

Previous
From: Anthony Bykov
Date:
Subject: Re: pgsql: Transforms for jsonb to PL/Perl
Next
From: Tom Lane
Date:
Subject: pgsql: Fix platform and Perl-version dependencies in new jsonb_plperlc