From e0f5048851ff88a53630a0c121a1cd15f6a2f1cd Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 4 Aug 2019 14:05:34 -0400 Subject: Fix handling of "undef" in contrib/jsonb_plperl. Perl has multiple internal representations of "undef", and just testing 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 where this module was added. Discussion: https://postgr.es/m/1564783533.324795401@f193.i.mail.ru --- contrib/jsonb_plperl/sql/jsonb_plperl.sql | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'contrib/jsonb_plperl/sql/jsonb_plperl.sql') diff --git a/contrib/jsonb_plperl/sql/jsonb_plperl.sql b/contrib/jsonb_plperl/sql/jsonb_plperl.sql index 8b062dfc6bb..a5b2cffe6b7 100644 --- a/contrib/jsonb_plperl/sql/jsonb_plperl.sql +++ b/contrib/jsonb_plperl/sql/jsonb_plperl.sql @@ -57,6 +57,19 @@ $$; SELECT testRegexpResultToJsonb(); +-- this revealed a different bug +CREATE FUNCTION testTextToJsonbObject(text) RETURNS jsonb +LANGUAGE plperl +TRANSFORM FOR TYPE jsonb +AS $$ +my $x = shift; +return {a => $x}; +$$; + +SELECT testTextToJsonbObject('abc'); +SELECT testTextToJsonbObject(NULL); + + CREATE FUNCTION roundtrip(val jsonb, ref text = '') RETURNS jsonb LANGUAGE plperl TRANSFORM FOR TYPE jsonb -- cgit v1.2.3