diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-06-18 15:31:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-06-18 15:31:57 -0400 |
commit | 3a382983d142ca270fe49c63fa6d4a95037ebee3 (patch) | |
tree | bea6c6e9210bd8aba153341f934b904a8de5709a /src | |
parent | e4300a3552b104f54ec781dd23cfcf96252ec5c1 (diff) | |
download | postgresql-3a382983d142ca270fe49c63fa6d4a95037ebee3.tar.gz postgresql-3a382983d142ca270fe49c63fa6d4a95037ebee3.zip |
Allow plperl_sv_to_datum to look through scalar refs.
There seems little reason for the policy of throwing error if we
find a ref to something other than a hash or array. Recursively
look through the ref, instead. This makes the behavior in non-transform
cases comparable to what was already instantiated for jsonb_plperl.
Note that because we invoke any available transform function before
considering the ref case, it's up to each transform function whether
it wants to play along with this behavior or do something different.
Because the previous behavior was just to throw a useless error,
this seems unlikely to create any compatibility issues. Still, given
the lack of field complaints so far, seems best not to back-patch.
Discussion: https://postgr.es/m/28336.1528393969@sss.pgh.pa.us
Diffstat (limited to 'src')
-rw-r--r-- | src/pl/plperl/expected/plperl.out | 9 | ||||
-rw-r--r-- | src/pl/plperl/plperl.c | 12 | ||||
-rw-r--r-- | src/pl/plperl/sql/plperl.sql | 2 |
3 files changed, 14 insertions, 9 deletions
diff --git a/src/pl/plperl/expected/plperl.out b/src/pl/plperl/expected/plperl.out index ebfba3eb8d0..d8a1ff5dd8d 100644 --- a/src/pl/plperl/expected/plperl.out +++ b/src/pl/plperl/expected/plperl.out @@ -763,14 +763,17 @@ $$ LANGUAGE plperl; SELECT text_obj(); ERROR: cannot convert Perl hash to non-composite type text CONTEXT: PL/Perl function "text_obj" ------ make sure we can't return a scalar ref +-- test looking through a scalar ref CREATE OR REPLACE FUNCTION text_scalarref() RETURNS text AS $$ my $str = 'str'; return \$str; $$ LANGUAGE plperl; SELECT text_scalarref(); -ERROR: PL/Perl function must return reference to hash or array -CONTEXT: PL/Perl function "text_scalarref" + text_scalarref +---------------- + str +(1 row) + -- check safe behavior when a function body is replaced during execution CREATE OR REPLACE FUNCTION self_modify(INTEGER) RETURNS INTEGER AS $$ spi_exec_query('CREATE OR REPLACE FUNCTION self_modify(INTEGER) RETURNS INTEGER AS \'return $_[0] * 3;\' LANGUAGE plperl;'); diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index 4342c02b272..4cfc5062531 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -1402,11 +1402,13 @@ plperl_sv_to_datum(SV *sv, Oid typid, int32 typmod, return ret; } - /* Reference, but not reference to hash or array ... */ - ereport(ERROR, - (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("PL/Perl function must return reference to hash or array"))); - return (Datum) 0; /* shut up compiler */ + /* + * If it's a reference to something else, such as a scalar, just + * recursively look through the reference. + */ + return plperl_sv_to_datum(SvRV(sv), typid, typmod, + fcinfo, finfo, typioparam, + isnull); } else { diff --git a/src/pl/plperl/sql/plperl.sql b/src/pl/plperl/sql/plperl.sql index c36da0ff043..b0d950b2304 100644 --- a/src/pl/plperl/sql/plperl.sql +++ b/src/pl/plperl/sql/plperl.sql @@ -504,7 +504,7 @@ $$ LANGUAGE plperl; SELECT text_obj(); ------ make sure we can't return a scalar ref +-- test looking through a scalar ref CREATE OR REPLACE FUNCTION text_scalarref() RETURNS text AS $$ my $str = 'str'; return \$str; |