pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Stuart McGraw <smcg4191@mtneva.com>
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: jsonb_set() strictness considered harmful to data
Date: Thu, 24 Oct 2019 21:15:42 +0200
Message-ID: <b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at> (raw)
In-Reply-To: <04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com>
References: <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>
	<CAKFQuwbkKPYhT0S6481L7temmiN+VNrMkExsUjp6FjJnCynd5A@mail.gmail.com>
	<5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com>
	<CAKmB1PEUO4nJMODBEob4ySHYSRX1EE8TUixYf=Dg-tFHfNnt1g@mail.gmail.com>
	<20191022225513.GA12201@hjp.at>
	<CAKFQuwYthEbaNT=xkj7RL7ZM7t=X+H+w4O36dShX=HtjkTYi+Q@mail.gmail.com>
	<d502306ecbad6b6fc5b02db80c82030c87e1497d.camel@cybertec.at>
	<04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com>

On Wed, 2019-10-23 at 13:00 -0600, Stuart McGraw wrote:
> > You can only say that if you don't understand NULL (you wouldn't be alone).
> > If I modify a JSON with an unknown value, the result is unknown.
> > This seems very intuitive to me.
> 
> Would you expect modifying an array value with an unknown would result
> in the entire array being unknown?

Hm, yes, that is less intuitive.
I was viewing a JSON as an atomic value above.

> > One could argue that whoever uses SQL should understand SQL.
> > 
> > But I believe that it is reasonable to suppose that many people who
> > use JSON in the database are more savvy with JSON than with SQL
> > (they might not have chosen JSON otherwise), so I agree that it makes
> > sense to change this particular behavior.
> 
> That (generally) SQL NULL results in NULL for any operation has been
> brought up multiple times in this thread, including above, as a rationale
> for the current jsonb behavior.  I don't think it is a valid argument.
> 
> When examples are given, they typically are with scalar values where
> such behavior makes sense: the resulting scalar value has to be NULL
> or non-NULL, it can't be both.
> 
> It is less sensible with compound values where the rule can apply to
> individual scalar components.  And indeed that is what Postgresql does
> for another compound type:
> 
>    # select array_replace(array[1,2,3],2,NULL);
>     array_replace
>    ---------------
>     {1,NULL,3}
> 
> The returned value is not NULL.  Why the inconsistency between the array
> type and json type?  Are there any cases other than json where the entire
> compound value is set to NULL as a result of one of its components being
> NULL?

That is a good point.

I agree that the behavior should be changed.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






view thread (83+ messages)  latest in thread

Message-ID: <b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at>
Permalink:  ../b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at/
Also on:    postgresql.org/message-id/b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at

 · 

reply

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: laurenz.albe@cybertec.at, smcg4191@mtneva.com
  Subject: Re: jsonb_set() strictness considered harmful to data
  In-Reply-To: <b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at>
  References: <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> <CAKFQuwbkKPYhT0S6481L7temmiN+VNrMkExsUjp6FjJnCynd5A@mail.gmail.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <CAKmB1PEUO4nJMODBEob4ySHYSRX1EE8TUixYf=Dg-tFHfNnt1g@mail.gmail.com> <20191022225513.GA12201@hjp.at> <CAKFQuwYthEbaNT=xkj7RL7ZM7t=X+H+w4O36dShX=HtjkTYi+Q@mail.gmail.com> <d502306ecbad6b6fc5b02db80c82030c87e1497d.camel@cybertec.at> <04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com> <b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at>

* 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