create table test add column data jsonb;insert into test values ( '[{ "name": "Alexa", "age": "20" }, { "name": "Siri", "age": "42" }]' );Table Data Looks like this:
data <------ column_name
[{"name": "Alexa", "age": "20"}, {"name": "Siri", "age": "42"}]
I am familiar with how to update json data, Here i want to take json data from array and change it.I want to change "name" attribute of first json object "Alexa" to "Cortana", Is it possible to do that is postgres?P.S. This is not the actual data that I have broken down my doubt to simple problem.
2 Answers2
You can use thejsonb_set function to return a JSON object with a section replaced with a new value
UPDATE testSET data = jsonb_set(data, '{0,name}', '"Cortana"', true)3 Comments
'null' as the third parameter, what did you try?Hopefully the following command also works.
update test set data = data - 0 || jsonb_build_object('name','Cortana', 'age', '20') returning *;Comments
Explore related questions
See similar questions with these tags.


