Re: Unexpected behavior of jsonb_set() with a `null` value

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: Марк <kolypto(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: Unexpected behavior of jsonb_set() with a `null` value
Date: 2019-09-12 14:11:52
Message-ID: db9745f5-0d85-ed97-9911-9644957be2fc@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Марк schrieb am 12.09.2019 um 12:55:
> With `jsonb_set()`, when `new_value` is `NULL`, the function would **erase the whole object**:
>
> postgres=# SELECT jsonb_set('{"something":1}'::jsonb, '{language}', null, true);         
> jsonb_set  
> -----------
>  
> (1 row)
>
> This is really dangerous for it may lead to data loss. Imaging the `new_value` argument being a function which returns `NULL` values in some cases.
> The expected behavior is, perhaps, to convert an SQL `NULL` value to JSONB null value: 'null'::jsonb
> This way no data would be lost.
>
> Or at the very least, this behavior should be documented.

I have asked the same: https://www.postgresql.org/message-id/flat/qfkua9%242q0e%241%40blaine.gmane.org

In short: not a bug ;)

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2019-09-12 14:32:00 Re: Unexpected behavior of jsonb_set() with a `null` value
Previous Message Magnus Hagander 2019-09-12 13:27:02 Re: BUG #16003: pg_basebackup failed with error : directory "xxxxxxx" exists but is not empty