Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdf521ab

Browse files
committed
Fix handling of "undef" in contrib/jsonb_plperl.
Perl has multiple internal representations of "undef", and justtesting for SvTYPE(x) == SVt_NULL doesn't recognize all of them,leading to "cannot transform this Perl type to jsonb" errors.Use the approved test SvOK() instead.Report and patch by Ivan Panchenko. Back-patch to v11 wherethis module was added.Discussion:https://postgr.es/m/1564783533.324795401@f193.i.mail.ru
1 parent4844c63 commitdf521ab

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

‎contrib/jsonb_plperl/expected/jsonb_plperl.out

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ SELECT testRegexpResultToJsonb();
6666
0
6767
(1 row)
6868

69+
-- this revealed a different bug
70+
CREATE FUNCTION testTextToJsonbObject(text) RETURNS jsonb
71+
LANGUAGE plperl
72+
TRANSFORM FOR TYPE jsonb
73+
AS $$
74+
my $x = shift;
75+
return {a => $x};
76+
$$;
77+
SELECT testTextToJsonbObject('abc');
78+
testtexttojsonbobject
79+
-----------------------
80+
{"a": "abc"}
81+
(1 row)
82+
83+
SELECT testTextToJsonbObject(NULL);
84+
testtexttojsonbobject
85+
-----------------------
86+
{"a": null}
87+
(1 row)
88+
6989
CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb
7090
LANGUAGE plperl
7191
TRANSFORM FOR TYPE jsonb
@@ -230,4 +250,4 @@ SELECT roundtrip('{"1": {"2": [3, 4, 5]}, "2": 3}', 'HASH');
230250

231251
\set VERBOSITY terse \\ -- suppress cascade details
232252
DROP EXTENSION plperl CASCADE;
233-
NOTICE: drop cascades to7 other objects
253+
NOTICE: drop cascades to8 other objects

‎contrib/jsonb_plperl/expected/jsonb_plperlu.out

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ SELECT testRegexpResultToJsonb();
6666
0
6767
(1 row)
6868

69+
-- this revealed a different bug
70+
CREATE FUNCTION testTextToJsonbObject(text) RETURNS jsonb
71+
LANGUAGE plperlu
72+
TRANSFORM FOR TYPE jsonb
73+
AS $$
74+
my $x = shift;
75+
return {a => $x};
76+
$$;
77+
SELECT testTextToJsonbObject('abc');
78+
testtexttojsonbobject
79+
-----------------------
80+
{"a": "abc"}
81+
(1 row)
82+
83+
SELECT testTextToJsonbObject(NULL);
84+
testtexttojsonbobject
85+
-----------------------
86+
{"a": null}
87+
(1 row)
88+
6989
CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb
7090
LANGUAGE plperlu
7191
TRANSFORM FOR TYPE jsonb
@@ -257,4 +277,4 @@ INFO: $VAR1 = {'1' => {'2' => ['3','4','5']},'2' => '3'};
257277

258278
\set VERBOSITY terse \\ -- suppress cascade details
259279
DROP EXTENSION plperlu CASCADE;
260-
NOTICE: drop cascades to7 other objects
280+
NOTICE: drop cascades to8 other objects

‎contrib/jsonb_plperl/jsonb_plperl.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ SV_to_JsonbValue(SV *in, JsonbParseState **jsonb_state, bool is_elem)
189189
caseSVt_PVHV:
190190
returnHV_to_JsonbValue((HV*)in,jsonb_state);
191191

192-
caseSVt_NULL:
193-
out.type=jbvNull;
194-
break;
195-
196192
default:
197-
if (SvUOK(in))
193+
if (!SvOK(in))
194+
{
195+
out.type=jbvNull;
196+
}
197+
elseif (SvUOK(in))
198198
{
199199
/*
200200
* If UV is >=64 bits, we have no better way to make this

‎contrib/jsonb_plperl/sql/jsonb_plperl.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ $$;
5757
SELECT testRegexpResultToJsonb();
5858

5959

60+
-- this revealed a different bug
61+
CREATEFUNCTIONtestTextToJsonbObject(text) RETURNS jsonb
62+
LANGUAGE plperl
63+
TRANSFORM FOR TYPE jsonb
64+
AS $$
65+
my $x= shift;
66+
return {a=> $x};
67+
$$;
68+
69+
SELECT testTextToJsonbObject('abc');
70+
SELECT testTextToJsonbObject(NULL);
71+
72+
6073
CREATEFUNCTIONroundtrip(val jsonb, reftext='') RETURNS jsonb
6174
LANGUAGE plperl
6275
TRANSFORM FOR TYPE jsonb

‎contrib/jsonb_plperl/sql/jsonb_plperlu.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ $$;
5757
SELECT testRegexpResultToJsonb();
5858

5959

60+
-- this revealed a different bug
61+
CREATEFUNCTIONtestTextToJsonbObject(text) RETURNS jsonb
62+
LANGUAGE plperlu
63+
TRANSFORM FOR TYPE jsonb
64+
AS $$
65+
my $x= shift;
66+
return {a=> $x};
67+
$$;
68+
69+
SELECT testTextToJsonbObject('abc');
70+
SELECT testTextToJsonbObject(NULL);
71+
72+
6073
CREATEFUNCTIONroundtrip(val jsonb, reftext='') RETURNS jsonb
6174
LANGUAGE plperlu
6275
TRANSFORM FOR TYPE jsonb

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp