Re: Transform for pl/perl
Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
From: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>, Tom Lane <tgl@sss.pgh.pa.us>
Cc: Pavel Stehule <pavel.stehule@gmail.com>,
Nikita Glukhov <n.gluhov@postgrespro.ru>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2018-04-24T18:31:24Z
Lists: pgsql-hackers
On 04/24/2018 12:17 PM, Peter Eisentraut wrote:
> On 4/10/18 10:31, Dagfinn Ilmari Mannsåker wrote:
>> Also, it doesn't parse back in as jsonb either:
>>
>> =# select jsonbnan()::text::json;
>> ERROR: invalid input syntax for type json
>> DETAIL: Token "NaN" is invalid.
>> CONTEXT: JSON data, line 1: NaN
>>
>> And it's inconsistent with to_jsonb():
>>
>> =# select to_jsonb('nan'::numeric);
>> ┌──────────┐
>> │ to_jsonb │
>> ├──────────┤
>> │ "NaN" │
>> └──────────┘
>>
>> It would be highly weird if PL transforms (jsonb_plpython does the same
>> thing) let you create spec-violating jsonb values that don't round-trip
>> via jsonb_out/in.
> Yeah this is not good. Is there a way to do this in a centralized way?
> Is there a function to check an internal jsonb value for consistency.
> Should at least the jsonb output function check and not print invalid
> values?
>
The output function fairly reasonably assumes that the jsonb is in a
form that would be parsed in by the input function. In particular, it
assumes that anything like a NaN will be stored as text and not as a
jsonb numeric. I don't think the transform should be doing anything
different from the input function.
There is the routine IsValidJsonNumber that helps - see among others
hstore_io.c for an example use.
cheers
andrew
--
Andrew Dunstan https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
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