In a table there is a column data(jsonb) and json array like this
[
{"pid": "123", "percentage": "10"},
{"pid": "456", "percentage": "50"},
{"pid": "789", "percentage": "40"}
]
I want to update percentage 30 where pid is 789. I used this query but not succeeded.
UPDATE table
SET data =
jsonb_set(data, '{pid}'::text[], data->'pid' || '{"percentage":"30"}'::jsonb)
WHERE (data->> 'pid') = '789' and id= '1'; [id is table's primary key]