Re: jsonb_set() strictness considered harmful to data

Поиск
Список
Период
Сортировка
От Peter J. Holzer
Тема Re: jsonb_set() strictness considered harmful to data
Дата
Msg-id 20191022230146.GB12201@hjp.at
обсуждение исходный текст
Ответ на Re: jsonb_set() strictness considered harmful to data  (Steven Pousty <steve.pousty@gmail.com>)
Список pgsql-general
On 2019-10-21 09:39:13 -0700, Steven Pousty wrote:
> Turning a JSON null into a SQL null  and thereby "deleting" the data
> is not the path of least surprises.

But it doesn't do that: A JSON null is perfectly fine:

wds=> select jsonb_set('{"a": 1, "b": 2}'::jsonb, '{c}', 'null'::jsonb);
╔═════════════════════════════╗
║          jsonb_set          ║
╟─────────────────────────────╢
║ {"a": 1, "b": 2, "c": null} ║
╚═════════════════════════════╝
(1 row)


It is trying to replace a part of the JSON object with an SQL NULL (i.e.
unknown) which returns SQL NULL:

wds=> select jsonb_set('{"a": 1, "b": 2}'::jsonb, '{c}', NULL);
╔═══════════╗
║ jsonb_set ║
╟───────────╢
║ (∅)       ║
╚═══════════╝
(1 row)

        hp

--
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>

Вложения

В списке pgsql-general по дате отправления:

Предыдущее
От: "Peter J. Holzer"
Дата:
Сообщение: Re: jsonb_set() strictness considered harmful to data
Следующее
От: "Peter J. Holzer"
Дата:
Сообщение: Re: jsonb_set() strictness considered harmful to data