From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Cc: Mark Felder <feld@FreeBSD.org>
Cc: pgsql-general@lists.postgresql.org
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: jsonb_set() strictness considered harmful to data
Date: Sat, 19 Oct 2019 18:18:51 +0200
Message-ID: <20191019161851.v7dwloiiav5yrpwu@development> (raw)
In-Reply-To: <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com>
References: <CAAOiGNwUsgM-UBqsJH_mriCFr-JCPxD+pQoXNvyOEQPc+YHQRQ@mail.gmail.com>
<d7a4e2b2-e009-4d79-aa5b-82bcf96aad2f@www.fastmail.com>
<7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com>
On Sat, Oct 19, 2019 at 11:26:50AM -0400, Andrew Dunstan wrote:
>
> ...
>
>The hyperbole here is misplaced. There is a difference between a bug and
>a POLA violation. This might be the latter, but it isn't the former. So
>please tone it down a bit. It's not the function that's unsafe, but the
>ill-informed use of it.
>
>
>We invented jsonb_set() (credit to Dmitry Dolgov). And we've had it
>since 9.5. That's five releases ago. So it's a bit late to be coming to
>us telling us it's not safe (according to your preconceptions of what it
>should be doing).
>
>
>We could change it prospectively (i.e. from release 13 on) if we choose.
>But absent an actual bug (i.e. acting contrary to documented behaviour)
>we do not normally backpatch such changes, especially when there is a
>simple workaround for the perceived problem. And it's that policy that
>is in large measure responsible for Postgres' deserved reputation for
>stability.
>
Yeah.
>
>Incidentally, why is your function written in plpgsql? Wouldn't a simple
>SQL wrapper be better?
>
>
> create or replace function safe_jsonb_set
> (target jsonb, path text[], new_value jsonb, create_missing
> boolean default true)
> returns jsonb as
> $func$
> select case when new_value is null then target else
> jsonb_set(target, path, new_value, create_missing) end
> $func$ language sql;
>
>
>And if we were to change it I'm not at all sure that we should do it the
>way that's suggested here, which strikes me as no more intuitive than
>the current behaviour. Rather I think we should possibly fill in a json
>null in the indicated place.
>
Not sure, but that seems rather confusing to me, because it's mixing SQL
NULL and JSON null, i.e. it's not clear to me why
jsonb_set(..., "...", NULL)
should do the same thing as
jsonb_set(..., "...", 'null':jsonb)
I'm not entirely surprised it's what MySQL does ;-) but I'd say treating
it as a deletion of the key (just like MSSQL) is somewhat more sensible.
But I admit it's quite subjective.
regards
--
Tomas Vondra http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tomas.vondra@2ndquadrant.com, andrew.dunstan@2ndquadrant.com, feld@FreeBSD.org, pgsql-hackers@lists.postgresql.org
Subject: Re: jsonb_set() strictness considered harmful to data
In-Reply-To: <20191019161851.v7dwloiiav5yrpwu@development>
References: <CAAOiGNwUsgM-UBqsJH_mriCFr-JCPxD+pQoXNvyOEQPc+YHQRQ@mail.gmail.com> <d7a4e2b2-e009-4d79-aa5b-82bcf96aad2f@www.fastmail.com> <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com> <20191019161851.v7dwloiiav5yrpwu@development>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox