Re: jsonb_set() strictness considered harmful to data

From: Andrew Dunstan <andrew(dot)dunstan(at)2ndquadrant(dot)com>
To: Floris Van Nee <florisvannee(at)Optiver(dot)com>, Ariadne Conill <ariadne(at)dereferenced(dot)org>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Mark Felder <feld(at)freebsd(dot)org>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: jsonb_set() strictness considered harmful to data
Date: 2019-10-20 12:31:38
Message-ID: 34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers


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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Isaac Morland 2019-10-20 13:42:59 Re: jsonb_set() strictness considered harmful to data
Previous Message Luca Ferrari 2019-10-20 09:35:04 UTC-6 or UTC+6?

Browse pgsql-hackers by date

  From Date Subject
Next Message Isaac Morland 2019-10-20 13:42:59 Re: jsonb_set() strictness considered harmful to data
Previous Message Tels 2019-10-20 11:48:13 Re: Declaring a strict function returns not null / eval speed