jsonb_set array append hack?
От | Thom Brown |
---|---|
Тема | jsonb_set array append hack? |
Дата | |
Msg-id | CAA-aLv59dToy02HNQd2wvFO8S5ZpLwQwtnsdoCGKehp7tCHrxA@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: jsonb_set array append hack?
|
Список | pgsql-hackers |
Hi,
I've noticed that if you use a string for an element key in jsonb_set with create_missing set to true, you can use it to append to an array:postgres=# SELECT jsonb_set(
'{"name": "Joe", "vehicle_types": ["car","van"]}'::jsonb,
'{vehicle_types,nonsense}',
'"motorcycle"', true);
jsonb_set
----------------------------------------------------------------
{"name": "Joe", "vehicle_types": ["car", "van", "motorcycle"]}
(1 row)
postgres=# SELECT jsonb_set(
'{"name": "Joe", "vehicle_types": ["car","van"]}'::jsonb,
'{vehicle_types,100000}',
'"motorcycle"', true);
jsonb_set
----------------------------------------------------------------
{"name": "Joe", "vehicle_types": ["car", "van", "motorcycle"]}
(1 row)
postgres=# SELECT jsonb_set(
'{"name": "Joe", "vehicle_types": ["car","van"]}'::jsonb,
array['vehicle_types',NULL],
'"motorcycle"', true);
Thom
В списке pgsql-hackers по дате отправления: