Re: Transform for pl/perl
Artur Zakirov <a.zakirov@postgrespro.ru>
From: Arthur Zakirov <a.zakirov@postgrespro.ru>
To: Anthony Bykov <a.bykov@postgrespro.ru>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>, pgsql-hackers@lists.postgresql.org
Date: 2018-01-31T10:36:22Z
Lists: pgsql-hackers
Hello,
On Fri, Jan 12, 2018 at 11:47:39AM +0300, Anthony Bykov wrote:
> Hello, thank you for your message.
> The problem was that different perl compilers uses different infinity
> representations. Some of them use "Inf" others - use "inf". So, in
> attachments there is a new version of the patch.
I've noticed a possible bug:
> + /* json key in v */
> + key = pstrdup(v.val.string.val);
> + keyLength = v.val.string.len;
> + JsonbIteratorNext(&it, &v, true);
I think it is worth to use pnstrdup() here, because v.val.string.val is
not necessarily null-terminated as the comment says:
> struct JsonbValue
> ...
> struct
> {
> int len;
> char *val; /* Not necessarily null-terminated */
> } string; /* String primitive type */
Consider an example:
=# CREATE FUNCTION testSVToJsonb3(val jsonb) RETURNS jsonb
LANGUAGE plperl
TRANSFORM FOR TYPE jsonb
AS $$
return $_->{"1"};
$$;
=# SELECT testSVToJsonb3('{"1":{"2":[3,4,5]},"2":3}');
testsvtojsonb3
----------------
(null)
But my perl isn't good, so the example maybe isn't good too.
--
Arthur Zakirov
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
Commits
-
Fix jsonb_plperl to convert Perl UV values correctly.
- 93b6e03ab479 11.0 landed
-
Fix contrib/hstore_plperl to look through scalar refs.
- e3b7f7cc5063 11.0 landed
- 7594b7a53366 10.5 landed
- 645929c545ef 9.5.14 landed
- 1bebfb9b6365 9.6.10 landed
-
Allow plperl_sv_to_datum to look through scalar refs.
- 3a382983d142 11.0 landed
-
Fix excessive enreferencing in jsonb-to-plperl transform.
- 1731e3741cbb 11.0 landed