aboutsummaryrefslogtreecommitdiff
path: root/contrib/jsonb_plperl/expected
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-06-18 14:31:42 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-06-18 14:31:42 -0400
commit1731e3741cbbf8e0b4481665d7d523bc55117f63 (patch)
treec22c6f731d3bb7644ef981366a0d3ef419c3973d /contrib/jsonb_plperl/expected
parent45e98ee730621fd34d0a132343cb3f906ccc8416 (diff)
downloadpostgresql-1731e3741cbbf8e0b4481665d7d523bc55117f63.tar.gz
postgresql-1731e3741cbbf8e0b4481665d7d523bc55117f63.zip
Fix excessive enreferencing in jsonb-to-plperl transform.
We want, say, 2 to be transformed as 2, not \\2 which is what the original coding produced. Perl's standard seems to be to add an RV wrapper only for hash and array SVs, so do it like that. This was missed originally because the test cases only checked what came out of a round trip back to SQL, and the strip-all-dereferences loop at the top of SV_to_JsonbValue hides the extra refs from view. As a better test, print the Perl value with Data::Dumper, like the hstore_plperlu tests do. While we can't do that in the plperl test, only plperlu, that should be good enough because this code is the same for both PLs. But also add a simplistic test for extra REFs, which we can do in both. That strip-all-dereferences behavior is now a bit dubious; it's unlike what happens for other Perl-to-SQL conversions. However, the best thing to do seems to be to leave it alone and make the other conversions act similarly. That will be done separately. Dagfinn Ilmari Mannsåker, adjusted a bit by me Discussion: https://postgr.es/m/d8jlgbq66t9.fsf@dalvik.ping.uio.no
Diffstat (limited to 'contrib/jsonb_plperl/expected')
-rw-r--r--contrib/jsonb_plperl/expected/jsonb_plperl.out49
-rw-r--r--contrib/jsonb_plperl/expected/jsonb_plperlu.out78
2 files changed, 87 insertions, 40 deletions
diff --git a/contrib/jsonb_plperl/expected/jsonb_plperl.out b/contrib/jsonb_plperl/expected/jsonb_plperl.out
index e4f3cdd41aa..d2d90eb4837 100644
--- a/contrib/jsonb_plperl/expected/jsonb_plperl.out
+++ b/contrib/jsonb_plperl/expected/jsonb_plperl.out
@@ -52,16 +52,19 @@ SELECT testRegexpResultToJsonb();
0
(1 row)
-CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb
+CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb
LANGUAGE plperl
TRANSFORM FOR TYPE jsonb
AS $$
+# can't use Data::Dumper, but let's at least check for unexpected ref type
+die 'unexpected '.(ref($_[0]) || 'not a').' reference'
+ if ref($_[0]) ne $_[1];
return $_[0];
$$;
-SELECT roundtrip('null');
- roundtrip
------------
- null
+SELECT roundtrip('null') is null;
+ ?column?
+----------
+ t
(1 row)
SELECT roundtrip('1');
@@ -115,91 +118,97 @@ SELECT roundtrip('false');
0
(1 row)
-SELECT roundtrip('[]');
+SELECT roundtrip('[]', 'ARRAY');
roundtrip
-----------
[]
(1 row)
-SELECT roundtrip('[null, null]');
+SELECT roundtrip('[null, null]', 'ARRAY');
roundtrip
--------------
[null, null]
(1 row)
-SELECT roundtrip('[1, 2, 3]');
+SELECT roundtrip('[1, 2, 3]', 'ARRAY');
roundtrip
-----------
[1, 2, 3]
(1 row)
-SELECT roundtrip('[-1, 2, -3]');
+SELECT roundtrip('[-1, 2, -3]', 'ARRAY');
roundtrip
-------------
[-1, 2, -3]
(1 row)
-SELECT roundtrip('[1.2, 2.3, 3.4]');
+SELECT roundtrip('[1.2, 2.3, 3.4]', 'ARRAY');
roundtrip
-----------------
[1.2, 2.3, 3.4]
(1 row)
-SELECT roundtrip('[-1.2, 2.3, -3.4]');
+SELECT roundtrip('[-1.2, 2.3, -3.4]', 'ARRAY');
roundtrip
-------------------
[-1.2, 2.3, -3.4]
(1 row)
-SELECT roundtrip('["string1", "string2"]');
+SELECT roundtrip('["string1", "string2"]', 'ARRAY');
roundtrip
------------------------
["string1", "string2"]
(1 row)
-SELECT roundtrip('{}');
+SELECT roundtrip('[["string1", "string2"]]', 'ARRAY');
+ roundtrip
+--------------------------
+ [["string1", "string2"]]
+(1 row)
+
+SELECT roundtrip('{}', 'HASH');
roundtrip
-----------
{}
(1 row)
-SELECT roundtrip('{"1": null}');
+SELECT roundtrip('{"1": null}', 'HASH');
roundtrip
-------------
{"1": null}
(1 row)
-SELECT roundtrip('{"1": 1}');
+SELECT roundtrip('{"1": 1}', 'HASH');
roundtrip
-----------
{"1": 1}
(1 row)
-SELECT roundtrip('{"1": -1}');
+SELECT roundtrip('{"1": -1}', 'HASH');
roundtrip
-----------
{"1": -1}
(1 row)
-SELECT roundtrip('{"1": 1.1}');
+SELECT roundtrip('{"1": 1.1}', 'HASH');
roundtrip
------------
{"1": 1.1}
(1 row)
-SELECT roundtrip('{"1": -1.1}');
+SELECT roundtrip('{"1": -1.1}', 'HASH');
roundtrip
-------------
{"1": -1.1}
(1 row)
-SELECT roundtrip('{"1": "string1"}');
+SELECT roundtrip('{"1": "string1"}', 'HASH');
roundtrip
------------------
{"1": "string1"}
(1 row)
-SELECT roundtrip('{"1": {"2": [3, 4, 5]}, "2": 3}');
+SELECT roundtrip('{"1": {"2": [3, 4, 5]}, "2": 3}', 'HASH');
roundtrip
---------------------------------
{"1": {"2": [3, 4, 5]}, "2": 3}
diff --git a/contrib/jsonb_plperl/expected/jsonb_plperlu.out b/contrib/jsonb_plperl/expected/jsonb_plperlu.out
index b44995058f2..3f5c5c681dd 100644
--- a/contrib/jsonb_plperl/expected/jsonb_plperlu.out
+++ b/contrib/jsonb_plperl/expected/jsonb_plperlu.out
@@ -52,154 +52,192 @@ SELECT testRegexpResultToJsonb();
0
(1 row)
-CREATE FUNCTION roundtrip(val jsonb) RETURNS jsonb
+CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb
LANGUAGE plperlu
TRANSFORM FOR TYPE jsonb
AS $$
+use Data::Dumper;
+$Data::Dumper::Sortkeys = 1;
+$Data::Dumper::Indent = 0;
+elog(INFO, Dumper($_[0]));
+die 'unexpected '.(ref($_[0]) || 'not a').' reference'
+ if ref($_[0]) ne $_[1];
return $_[0];
$$;
-SELECT roundtrip('null');
- roundtrip
------------
- null
+SELECT roundtrip('null') is null;
+INFO: $VAR1 = undef;
+ ?column?
+----------
+ t
(1 row)
SELECT roundtrip('1');
+INFO: $VAR1 = '1';
roundtrip
-----------
1
(1 row)
SELECT roundtrip('1E+131071');
+INFO: $VAR1 = 'inf';
ERROR: cannot convert infinity to jsonb
CONTEXT: PL/Perl function "roundtrip"
SELECT roundtrip('-1');
+INFO: $VAR1 = '-1';
roundtrip
-----------
-1
(1 row)
SELECT roundtrip('1.2');
+INFO: $VAR1 = '1.2';
roundtrip
-----------
1.2
(1 row)
SELECT roundtrip('-1.2');
+INFO: $VAR1 = '-1.2';
roundtrip
-----------
-1.2
(1 row)
SELECT roundtrip('"string"');
+INFO: $VAR1 = 'string';
roundtrip
-----------
"string"
(1 row)
SELECT roundtrip('"NaN"');
+INFO: $VAR1 = 'NaN';
roundtrip
-----------
"NaN"
(1 row)
SELECT roundtrip('true');
+INFO: $VAR1 = '1';
roundtrip
-----------
1
(1 row)
SELECT roundtrip('false');
+INFO: $VAR1 = '0';
roundtrip
-----------
0
(1 row)
-SELECT roundtrip('[]');
+SELECT roundtrip('[]', 'ARRAY');
+INFO: $VAR1 = [];
roundtrip
-----------
[]
(1 row)
-SELECT roundtrip('[null, null]');
+SELECT roundtrip('[null, null]', 'ARRAY');
+INFO: $VAR1 = [undef,undef];
roundtrip
--------------
[null, null]
(1 row)
-SELECT roundtrip('[1, 2, 3]');
+SELECT roundtrip('[1, 2, 3]', 'ARRAY');
+INFO: $VAR1 = ['1','2','3'];
roundtrip
-----------
[1, 2, 3]
(1 row)
-SELECT roundtrip('[-1, 2, -3]');
+SELECT roundtrip('[-1, 2, -3]', 'ARRAY');
+INFO: $VAR1 = ['-1','2','-3'];
roundtrip
-------------
[-1, 2, -3]
(1 row)
-SELECT roundtrip('[1.2, 2.3, 3.4]');
+SELECT roundtrip('[1.2, 2.3, 3.4]', 'ARRAY');
+INFO: $VAR1 = ['1.2','2.3','3.4'];
roundtrip
-----------------
[1.2, 2.3, 3.4]
(1 row)
-SELECT roundtrip('[-1.2, 2.3, -3.4]');
+SELECT roundtrip('[-1.2, 2.3, -3.4]', 'ARRAY');
+INFO: $VAR1 = ['-1.2','2.3','-3.4'];
roundtrip
-------------------
[-1.2, 2.3, -3.4]
(1 row)
-SELECT roundtrip('["string1", "string2"]');
+SELECT roundtrip('["string1", "string2"]', 'ARRAY');
+INFO: $VAR1 = ['string1','string2'];
roundtrip
------------------------
["string1", "string2"]
(1 row)
-SELECT roundtrip('{}');
+SELECT roundtrip('[["string1", "string2"]]', 'ARRAY');
+INFO: $VAR1 = [['string1','string2']];
+ roundtrip
+--------------------------
+ [["string1", "string2"]]
+(1 row)
+
+SELECT roundtrip('{}', 'HASH');
+INFO: $VAR1 = {};
roundtrip
-----------
{}
(1 row)
-SELECT roundtrip('{"1": null}');
+SELECT roundtrip('{"1": null}', 'HASH');
+INFO: $VAR1 = {'1' => undef};
roundtrip
-------------
{"1": null}
(1 row)
-SELECT roundtrip('{"1": 1}');
+SELECT roundtrip('{"1": 1}', 'HASH');
+INFO: $VAR1 = {'1' => '1'};
roundtrip
-----------
{"1": 1}
(1 row)
-SELECT roundtrip('{"1": -1}');
+SELECT roundtrip('{"1": -1}', 'HASH');
+INFO: $VAR1 = {'1' => '-1'};
roundtrip
-----------
{"1": -1}
(1 row)
-SELECT roundtrip('{"1": 1.1}');
+SELECT roundtrip('{"1": 1.1}', 'HASH');
+INFO: $VAR1 = {'1' => '1.1'};
roundtrip
------------
{"1": 1.1}
(1 row)
-SELECT roundtrip('{"1": -1.1}');
+SELECT roundtrip('{"1": -1.1}', 'HASH');
+INFO: $VAR1 = {'1' => '-1.1'};
roundtrip
-------------
{"1": -1.1}
(1 row)
-SELECT roundtrip('{"1": "string1"}');
+SELECT roundtrip('{"1": "string1"}', 'HASH');
+INFO: $VAR1 = {'1' => 'string1'};
roundtrip
------------------
{"1": "string1"}
(1 row)
-SELECT roundtrip('{"1": {"2": [3, 4, 5]}, "2": 3}');
+SELECT roundtrip('{"1": {"2": [3, 4, 5]}, "2": 3}', 'HASH');
+INFO: $VAR1 = {'1' => {'2' => ['3','4','5']},'2' => '3'};
roundtrip
---------------------------------
{"1": {"2": [3, 4, 5]}, "2": 3}