Re: jsonb_set() strictness considered harmful to data
От | Paul A Jungwirth |
---|---|
Тема | Re: jsonb_set() strictness considered harmful to data |
Дата | |
Msg-id | CA+renyW3jsJSoMtsa0PrvQhj9iTu5=Y-oVbAi5A92+CrgdU9TQ@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: jsonb_set() strictness considered harmful to data (Laurenz Albe <laurenz.albe@cybertec.at>) |
Список | pgsql-general |
> That said, I think it is reasonable that a PostgreSQL JSON function > behaves in the way that JSON users would expect, so here is my +1 for > interpreting an SQL NULL as a JSON null in the above case Just to chime in as another application developer: the current functionality does seem pretty surprising and dangerous to me. Raising an exception seems pretty annoying. Setting the key's value to a JSON null would be fine, but I also like the idea of removing the key entirely, since that gives you strictly more functionality: you can always set the key to a JSON null by passing one in, if that's what you want. But there are lots of other functions that convert SQL NULL to JSON null: postgres=# select row_to_json(row(null)), json_build_object('foo', null), json_object(array['foo', null]), json_object(array['foo'], array[null]); row_to_json | json_build_object | json_object | json_object -------------+-------------------+----------------+---------------- {"f1":null} | {"foo" : null} | {"foo" : null} | {"foo" : null} (1 row) (The jsonb variants give the same results.) I think those functions are very similar to json_set here, and I'd expect json_set to do what they do (i.e. convert SQL NULL to JSON null). Paul
В списке pgsql-general по дате отправления: