append
UPDATE jsontesting SET jsondata = jsondata || '["newString"]'::jsonb WHERE id = 7;
remove
UPDATE jsontesting SET jsondata = jsondata - "newString" WHERE id = 7;
nested append
UPDATE jsontesting SET jsondata = jsonb_set( jsondata::jsonb, array['nestedfield'], (jsondata->'nestedfield')::jsonb || '["newString"]'::jsonb) WHERE id = 7;
Splice by index
UPDATE ${table} SET ${col} = ${col} - ( SELECT i FROM generate_series(0, jsonb_array_length(${col}) - 1) AS i WHERE (${col}->i->'id' = '"${id}"') ) WHERE ${table}.id = '${where}'::uuid
Splice by index of object array
itectec.com
I am attempting to remove an element from my database. The element I want to remove is within a JSON object called playerContainer which contains an array named players. This all sits within a table called site_content. I am trying to remove the object based on it's ID.
https://itectec.com/database/postgresql-delete-an-object-from-within-an-array-using-jsonb-in-postgresql/
Append and remove simple
Appending (pushing) and removing from a JSON array in PostgreSQL 9.5+
For versions less than 9.5 see this question I have created a table in PostgreSQL using this: CREATE TEMP TABLE jsontesting AS SELECT id, jsondata::jsonb FROM ( VALUES (1, '["abra","value",...
https://stackoverflow.com/questions/42233542/appending-pushing-and-removing-from-a-json-array-in-postgresql-9-5
