Re: jsonb_set() strictness considered harmful to data

From: Ariadne Conill <ariadne(at)dereferenced(dot)org>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, Christoph Moench-Tegeder <cmt(at)burggraben(dot)net>, "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>, "feld(at)freebsd(dot)org" <feld(at)freebsd(dot)org>
Subject: Re: jsonb_set() strictness considered harmful to data
Date: 2019-10-19 06:52:11
Message-ID: CAAOiGNx=xxhPxfFwa71iwfqLw7Ns-mdMVjs1AnHq0z=fH4sd3w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Hello,

On Sat, Oct 19, 2019 at 12:52 AM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
>
>
> so 19. 10. 2019 v 7:41 odesílatel David G. Johnston <david(dot)g(dot)johnston(at)gmail(dot)com> napsal:
>>
>> On Friday, October 18, 2019, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>>
>>>
>>> Probably there will be some applications that needs NULL result in situations when value was not changed or when input value has not expected format. Design using in Postgres allows later customization - you can implement with COALESCE very simply behave that you want (sure, you have to know what you do). If Postgres implement design used by MySQL, then there is not any possibility to react on situation when update is not processed.
>>
>>
>> A CASE expression seems like it would work well for such detection in the rare case it is needed. Current behavior is unsafe with minimal or no redeeming qualities. Change it so passing in null raises an exception and make the user decide their own behavior if we don’t want to choose one for them.
>
>
> How you can do it? Buildn functions cannot to return more than one value. The NULL is one possible signal how to emit this informations.
>
> The NULL value can be problem everywhere - and is not consistent to raise exception somewhere and elsewhere not.
>
> I agree so the safe way is raising exception on NULL. Unfortunately, exception handling is pretty expensive in Postres (more in write transactions), so it should be used only when it is really necessary.

I would say that any thing like

update whatever set column=jsonb_set(column, '{foo}', NULL)

should throw an exception. It should do, literally, *anything* else
but blank that column.

Ariadne

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tomas Vondra 2019-10-19 11:08:31 Re: jsonb_set() strictness considered harmful to data
Previous Message Pavel Stehule 2019-10-19 05:52:13 Re: jsonb_set() strictness considered harmful to data

Browse pgsql-hackers by date

  From Date Subject
Next Message Etsuro Fujita 2019-10-19 08:56:02 Re: Obsolete comment in partbounds.c
Previous Message Pavel Stehule 2019-10-19 05:52:13 Re: jsonb_set() strictness considered harmful to data