Re: [PATCH] Generalized JSON output functions

From: "Shulgin, Oleksandr" <oleksandr(dot)shulgin(at)zalando(dot)de>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Ryan Pedela <rpedela(at)datalanche(dot)com>, hlinnaka(at)iki(dot)fi, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: [PATCH] Generalized JSON output functions
Date: 2015-07-13 09:41:04
Message-ID: CACACo5Q3jzN5FiWeE31rSW4Ld5vk8TZv3U8b62pQgrupPvNP0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jul 13, 2015 at 9:44 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
wrote:

>
> To reiterate: for my problem, that is escaping numerics that can
>> potentially overflow[1] under ECMAScript standard, I want to be able to
>> override the code that outputs the numeric converted to string. There is
>> no way in current implementation to do that *at all*, short of copying all
>> the code involved in producing JSON output and changing it at certain
>> points. One could try re-parsing JSON instead, but that doesn't actually
>> solve the issue, because type information is lost forever at that point.
>>
>> The whitespace unification was a mere side-effect of the original effort
>> on this patch.
>>
>
> The dynamic type change is some what I would not to do in database, really
> :)
>
> If you afraid about overflow, then convert numeric to string immediately -
> in this case, the client have to support both variant - so immediate cast
> should not be a problem.
>

Yeah, but how would you do that in context of a logical replication
decoding plugin? I've tried a number of tricks for that, including, but
not limited to registering phony types to wrap numeric type and replacing
the OID of numeric with this custom type OID in TupleDesc, but then again
one has to register that as known record type, etc.

Anyway this check on max number should be implemented in our JSON(b) out
> functions (as warning?).
>

Not really, since this is a problem of ECMAScript standard, not JSON spec.
For example, Python module for handling JSON doesn't suffer from this
overflow problem,

The thing is, we cannot know which clients are going to consume the stream
of decoded events, and if it's some implementation of JavaScript, it can
suffer silent data corruption if we don't guard against that in the logical
decoding plugin.

Hope that makes it clear. :-)

--
Alex

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ildus Kurbangaliev 2015-07-13 09:56:39 Re: RFC: replace pg_stat_activity.waiting with something more descriptive
Previous Message Kyotaro HORIGUCHI 2015-07-13 08:51:44 Re: multivariate statistics / patch v7