Re: jsonb_set() strictness considered harmful to data

Поиск
Список
Период
Сортировка
От Andrew Dunstan
Тема Re: jsonb_set() strictness considered harmful to data
Дата
Msg-id 544ecc1e-681e-69f1-5cde-8b8aaeb45d7f@2ndQuadrant.com
обсуждение исходный текст
Ответ на Re: jsonb_set() strictness considered harmful to data  (Tomas Vondra <tomas.vondra@2ndquadrant.com>)
Ответы Re: jsonb_set() strictness considered harmful to data  (Andrew Dunstan <andrew.dunstan@2ndquadrant.com>)
Re: jsonb_set() strictness considered harmful to data  (Andrew Dunstan <andrew.dunstan@2ndquadrant.com>)
Список pgsql-general
On 10/21/19 2:07 AM, Tomas Vondra wrote:
> On Sun, Oct 20, 2019 at 06:51:05PM -0400, Andrew Dunstan wrote:
>>
>>> I think the general premise of this thread is that the application
>>> developer does not realize that may be necessary, because it's a bit
>>> surprising behavior, particularly when having more experience with
>>> other
>>> databases that behave differently. It's also pretty easy to not notice
>>> this issue for a long time, resulting in significant data loss.
>>>
>>> Let's say you're used to the MSSQL or MySQL behavior, you migrate your
>>> application to PostgreSQL or whatever - how do you find out about this
>>> behavior? Users are likely to visit
>>>
>>>    https://www.postgresql.org/docs/12/functions-json.html
>>>
>>> but that says nothing about how jsonb_set works with NULL values :-(
>>
>>
>>
>> We should certainly fix that. I accept some responsibility for the
>> omission.
>>
>
> +1
>
>


So let's add something to the JSON funcs page  like this:


Note: All the above functions except for json_build_object,
json_build_array, json_to_recordset, json_populate_record, and
json_populate_recordset and their jsonb equivalents are strict
functions. That is, if any argument is NULL the function result will be
NULL and the function won't even be called. Particular care should
therefore be taken to avoid passing NULL arguments to those functions
unless a NULL result is expected. This is particularly true of the
jsonb_set and jsonb_insert functions.



(We do have a heck of a lot of Note: sections on that page)


cheers


andrew



-- 
Andrew Dunstan                https://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




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

Предыдущее
От: Fabio Ugo Venchiarutti
Дата:
Сообщение: Re: Postgres Point in time Recovery (PITR),
Следующее
От: Alexander Farber
Дата:
Сообщение: Calling jsonb_array_elements 4 times in the same query