In my PostgreSQL database I have the following schema:
CREATE TABLE survey_results (
id integer,
data jsonb DEFAULT '{}'::jsonb
);
INSERT INTO survey_results (id, data)
VALUES (1, '{"user": {}, "survey": {}}');
INSERT INTO survey_results (id, data)
VALUES (2, '{"user": {}, "survey": {}}');
I want to update all records in survey_results table to have the following values in data column:
{"user":{"dob": '1995'},"survey":{"id": '1234'}}
How can I do that? I tried to do that with jsonb_set but I was not able to set all keys. Any ideas?
Here is sqlfiddle: