From: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
To: Floris Van Nee <florisvannee@Optiver.com>
To: Ariadne Conill <ariadne@dereferenced.org>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Mark Felder <feld@freebsd.org>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: jsonb_set() strictness considered harmful to data
Date: Sun, 20 Oct 2019 08:31:38 -0400
Message-ID: <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> (raw)
In-Reply-To: <1571560798575.47024@Optiver.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>
<20191019161851.v7dwloiiav5yrpwu@development>
<CAKFQuwa0epfqMsJ=yz8t+ASmdf5PoFXhXj=9DBpoHa2i_67nJw@mail.gmail.com>
<a2c965cc-7d90-ed89-d50f-b2c046d4499e@2ndQuadrant.com>
<20191019192723.luarxhq57qkzuncw@development>
<CAAOiGNxmXSUdOzBg+7vWMzTjDELmiZi_dqGz355tKy+OgbCZpA@mail.gmail.com>
<1571560798575.47024@Optiver.com>
On 10/20/19 4:39 AM, Floris Van Nee wrote:
>
> FWIW I've been bitten by this 'feature' more than once as well,
> accidentally erasing a column. Now I usually write js = jsonb_set(js,
> coalesce(new_column, 'null'::jsonb)) to prevent erasing the whole
> column, and instead setting the value to a jsonb null value, but I
> also found the STRICT behavior very surprising at first..
>
>
>
Understood. I think the real question here is what it should do instead
when the value is NULL. Your behaviour above is one suggestion, which I
personally find intuitive. Another has been to remove the associated
key. Another is to return the original target. And yet another is to
raise an exception, which is easy to write but really punts the issue
back to the application programmer who will have to decide how to ensure
they never pass in a NULL parameter. Possibly we could even add an extra
parameter to specify what should be done.
Also, the question will arise what to do when any of the other
parameters are NULL. Should we return NULL in those cases as we do now?
cheers
andrew
--
Andrew Dunstan https://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: andrew.dunstan@2ndquadrant.com, florisvannee@Optiver.com, ariadne@dereferenced.org, tomas.vondra@2ndquadrant.com, david.g.johnston@gmail.com, feld@freebsd.org, pgsql-hackers@lists.postgresql.org
Subject: Re: jsonb_set() strictness considered harmful to data
In-Reply-To: <34a7ff88-0d86-0990-4eac-48159df8d7f2@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> <20191019161851.v7dwloiiav5yrpwu@development> <CAKFQuwa0epfqMsJ=yz8t+ASmdf5PoFXhXj=9DBpoHa2i_67nJw@mail.gmail.com> <a2c965cc-7d90-ed89-d50f-b2c046d4499e@2ndQuadrant.com> <20191019192723.luarxhq57qkzuncw@development> <CAAOiGNxmXSUdOzBg+7vWMzTjDELmiZi_dqGz355tKy+OgbCZpA@mail.gmail.com> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com>
* 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