2018-04-03 15:47:18 +02:00
|
|
|
CREATE EXTENSION jsonb_plperl CASCADE;
|
|
|
|
NOTICE: installing required extension "plperl"
|
|
|
|
CREATE FUNCTION testHVToJsonb() RETURNS jsonb
|
|
|
|
LANGUAGE plperl
|
|
|
|
TRANSFORM FOR TYPE jsonb
|
|
|
|
AS $$
|
|
|
|
$val = {a => 1, b => 'boo', c => undef};
|
|
|
|
return $val;
|
|
|
|
$$;
|
|
|
|
SELECT testHVToJsonb();
|
|
|
|
testhvtojsonb
|
|
|
|
---------------------------------
|
|
|
|
{"a": 1, "b": "boo", "c": null}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
CREATE FUNCTION testAVToJsonb() RETURNS jsonb
|
|
|
|
LANGUAGE plperl
|
|
|
|
TRANSFORM FOR TYPE jsonb
|
|
|
|
AS $$
|
|
|
|
$val = [{a => 1, b => 'boo', c => undef}, {d => 2}];
|
|
|
|
return $val;
|
|
|
|
$$;
|
|
|
|
SELECT testAVToJsonb();
|
|
|
|
testavtojsonb
|
|
|
|
---------------------------------------------
|
|
|
|
[{"a": 1, "b": "boo", "c": null}, {"d": 2}]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
CREATE FUNCTION testSVToJsonb() RETURNS jsonb
|
|
|
|
LANGUAGE plperl
|
|
|
|
TRANSFORM FOR TYPE jsonb
|
|
|
|
AS $$
|
|
|
|
$val = 1;
|
|
|
|
return $val;
|
|
|
|
$$;
|
|
|
|
SELECT testSVToJsonb();
|
|
|
|
testsvtojsonb
|
|
|
|
---------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
Fix platform and Perl-version dependencies in new jsonb_plperl code.
Testing SvTYPE() directly is more fraught with problems than one might
think, because depending on context Perl might be storing a scalar value
in one of several forms, eg both numeric and string values. This resulted
in Perl-version-dependent buildfarm test failures. Instead use the SvTYPE
test only to distinguish non-scalar cases (AV, HV, NULL). Disambiguate
scalars by testing SvIOK, SvNOK, then SvPOK. This creates a preference
order for how we will resolve cases where the value is available in more
than one form, which seems fine to me.
Furthermore, because we're now dealing directly with a "double" value
in the SvNOK case, we can get rid of an inadequate and unportable
string-comparison test for infinities, and use isinf() instead.
(We do need some additional #include and "-lm" infrastructure to use
that in a contrib module, per prior experiences.)
In passing, prevent the regression test results from depending on DROP
CASCADE order; I've not seen that malfunction, but it's trouble waiting
to happen.
Discussion: https://postgr.es/m/E1f3MMJ-0006bf-B0@gemulon.postgresql.org
2018-04-04 17:28:33 +02:00
|
|
|
-- this revealed a bug in the original implementation
|
|
|
|
CREATE FUNCTION testRegexpResultToJsonb() RETURNS jsonb
|
|
|
|
LANGUAGE plperl
|
|
|
|
TRANSFORM FOR TYPE jsonb
|
|
|
|
AS $$
|
|
|
|
return ('1' =~ m(0\t2));
|
|
|
|
$$;
|
|
|
|
SELECT testRegexpResultToJsonb();
|
|
|
|
testregexpresulttojsonb
|
|
|
|
-------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
2018-04-03 15:47:18 +02:00
|
|
|
CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb
|
|
|
|
LANGUAGE plperl
|
|
|
|
TRANSFORM FOR TYPE jsonb
|
|
|
|
AS $$
|
|
|
|
return $_[0];
|
|
|
|
$$;
|
|
|
|
SELECT roundtrip('null');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
null
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('1');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('1E+131071');
|
2018-04-30 18:28:45 +02:00
|
|
|
ERROR: cannot convert infinity to jsonb
|
2018-04-03 15:47:18 +02:00
|
|
|
CONTEXT: PL/Perl function "roundtrip"
|
|
|
|
SELECT roundtrip('-1');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
-1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('1.2');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
1.2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('-1.2');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
-1.2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('"string"');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
"string"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('"NaN"');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
"NaN"
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('true');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('false');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('[]');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
[]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('[null, null]');
|
|
|
|
roundtrip
|
|
|
|
--------------
|
|
|
|
[null, null]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('[1, 2, 3]');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
[1, 2, 3]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('[-1, 2, -3]');
|
|
|
|
roundtrip
|
|
|
|
-------------
|
|
|
|
[-1, 2, -3]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('[1.2, 2.3, 3.4]');
|
|
|
|
roundtrip
|
|
|
|
-----------------
|
|
|
|
[1.2, 2.3, 3.4]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('[-1.2, 2.3, -3.4]');
|
|
|
|
roundtrip
|
|
|
|
-------------------
|
|
|
|
[-1.2, 2.3, -3.4]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('["string1", "string2"]');
|
|
|
|
roundtrip
|
|
|
|
------------------------
|
|
|
|
["string1", "string2"]
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{}');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
{}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": null}');
|
|
|
|
roundtrip
|
|
|
|
-------------
|
|
|
|
{"1": null}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": 1}');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
{"1": 1}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": -1}');
|
|
|
|
roundtrip
|
|
|
|
-----------
|
|
|
|
{"1": -1}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": 1.1}');
|
|
|
|
roundtrip
|
|
|
|
------------
|
|
|
|
{"1": 1.1}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": -1.1}');
|
|
|
|
roundtrip
|
|
|
|
-------------
|
|
|
|
{"1": -1.1}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": "string1"}');
|
|
|
|
roundtrip
|
|
|
|
------------------
|
|
|
|
{"1": "string1"}
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT roundtrip('{"1": {"2": [3, 4, 5]}, "2": 3}');
|
|
|
|
roundtrip
|
|
|
|
---------------------------------
|
|
|
|
{"1": {"2": [3, 4, 5]}, "2": 3}
|
|
|
|
(1 row)
|
|
|
|
|
Fix platform and Perl-version dependencies in new jsonb_plperl code.
Testing SvTYPE() directly is more fraught with problems than one might
think, because depending on context Perl might be storing a scalar value
in one of several forms, eg both numeric and string values. This resulted
in Perl-version-dependent buildfarm test failures. Instead use the SvTYPE
test only to distinguish non-scalar cases (AV, HV, NULL). Disambiguate
scalars by testing SvIOK, SvNOK, then SvPOK. This creates a preference
order for how we will resolve cases where the value is available in more
than one form, which seems fine to me.
Furthermore, because we're now dealing directly with a "double" value
in the SvNOK case, we can get rid of an inadequate and unportable
string-comparison test for infinities, and use isinf() instead.
(We do need some additional #include and "-lm" infrastructure to use
that in a contrib module, per prior experiences.)
In passing, prevent the regression test results from depending on DROP
CASCADE order; I've not seen that malfunction, but it's trouble waiting
to happen.
Discussion: https://postgr.es/m/E1f3MMJ-0006bf-B0@gemulon.postgresql.org
2018-04-04 17:28:33 +02:00
|
|
|
\set VERBOSITY terse \\ -- suppress cascade details
|
2018-04-03 15:47:18 +02:00
|
|
|
DROP EXTENSION plperl CASCADE;
|
2018-05-01 19:21:16 +02:00
|
|
|
NOTICE: drop cascades to 6 other objects
|