Re: jsonb_set() strictness considered harmful to data

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Stuart McGraw <smcg4191(at)mtneva(dot)com>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: jsonb_set() strictness considered harmful to data
Date: 2019-10-24 19:15:42
Message-ID: b7749bdfd275ae8adf1879016bad730ed6738cd1.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Daniel Verite 2019-10-24 19:39:32 Re: SQL Error [0A000]: ERROR: nondeterministic collations are not supported for LIKE
Previous Message Laurenz Albe 2019-10-24 19:09:30 Re: Recover databases from raw files (only exists the base directory)

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-10-24 20:17:58 Re: jsonb_set() strictness considered harmful to data
Previous Message Alvaro Herrera 2019-10-24 18:48:57 Re: Creating foreign key on partitioned table is too slow