PostgreSQL rename attribute in jsonb field

In UPDATE use delete (-) and concatenate (||) operators, e.g.: create table example(id int primary key, js jsonb); insert into example values (1, ‘{“nme”: “test”}’), (2, ‘{“nme”: “second test”}’); update example set js = js – ‘nme’ || jsonb_build_object(‘name’, js->’nme’) where js ? ‘nme’ returning *; id | js —-+————————- 1 | {“name”: “test”} 2 … Read more

Appending (pushing) and removing from a JSON array in PostgreSQL 9.5+

To add the value use the JSON array append opperator (||) UPDATE jsontesting SET jsondata = jsondata || ‘[“newString”]’::jsonb WHERE id = 7; Removing the value looks like this UPDATE jsontesting SET jsondata = jsondata – ‘newString’ WHERE id = 7; Concatenating to a nested field looks like this UPDATE jsontesting SET jsondata = jsonb_set( … Read more