Json Request
INSERT INTO test.demotbl (data)
VALUES ('{
"x1": "Americas",
"x2": "West",
"x3": [{
"x_id": "sam"
}],
"x4": {
"a1": true,
"a2": false,
"a3": [
"xx",
"xx"
],
"a4": [
"Josh"
],
"y1": [{
"id": "RW",
"z2": true,
"z3": "USER"
},
{
"id": "RO",
"z2": false,
"z3": "SELECT"
}
]
}
}'::jsonb)
I want to update a new filed z4 based on id condition "id": "RO".Eample "z4": [{ "name": "john" }, { "name": "Steve" }
expected output :
{
"x1": "Americas",
"x2": "West",
"x3": [{
"x_id": "sam"
}],
"x4": {
"a1": true,
"a2": false,
"a3": [
"xx",
"xx"
],
"a4": [
"Josh"
],
"y1": [{
"id": "RW",
"z2": true,
"z3": "USER"
},
{
"id": "RO",
"z2": false,
"z3": "SELECT",
"z4": [{
"name": "john"
},{
"name": "Steve"
}]
}
]
}
}
what postgres JSONB sql i can use to achive the above output?