I have created a table in postgreSQL using this:
create table jsontesting (
id INTEGER,
jsondata JSONB
);
and added some rows to it:
INSERT into jsontesting VALUES (1, '["abra","value","mango", "apple", "sample"]'::jsonb);
INSERT into jsontesting VALUES (2, '["japan","china","india", "russia", "australia"]'::jsonb);
INSERT into jsontesting VALUES (3, '["must", "match"]'::jsonb);
INSERT into jsontesting VALUES (4, '["abra","value","true", "apple", "sample"]'::jsonb);
INSERT into jsontesting VALUES (5, '["abra","false","mango", "apple", "sample"]'::jsonb);
INSERT into jsontesting VALUES (6, '["string","value","mango", "apple", "sample"]'::jsonb);
INSERT into jsontesting VALUES (7, '["must", "watch"]'::jsonb);
now what I wanted was to add or remove a value from the json data array.something like update jsontesting set jsondata=append_to_json_array(jsondata, 'newString') WHERE id = 7;
where the function append_to_json_array takes in the actual jsondata which is a json-array and the newString which I have to add to that jsondata array and this function should return the updated json-array.Similarly one function for removing the value. I tried to search documentation of postgreSQL but found nothing there.
I used a json because I wanted to store an array of keys for a particular id(user). These keys are provided by user thus they can add/remove values. I dont wanted to create mutiple rows for this. so I created a json array.