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

From: Марк <kolypto(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Unexpected behavior of jsonb_set() with a `null` value
Date: 2019-09-12 10:55:59
Message-ID: CAOA+1AxbrhVm0HBTDcB97Gmtwp2Nc_qUv2tTbKESusoAQVBexw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Dear Support Team,

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.

Thank you in advance,
Mark

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2019-09-12 11:17:47 BUG #16004: New Version pgrouting_96-2.6.3-1 has dependency to postgis25_96 in postgresql.org-Channel
Previous Message PG Bug reporting form 2019-09-12 08:40:11 BUG #16003: pg_basebackup failed with error : directory "xxxxxxx" exists but is not empty