I have DB table with jsonb column.
number | data
1 | {"name": "firstName", "city": "toronto", "province": "ON"}
I need a way to update data column. So my output should look like:
{"name": "firstName", "city": "ottawa", "province": "ON", "phone": "phonenum", "prefix": "prefixedName"}
Is it possible with json_set? I have added query like:
update table_name set data = jsonb_set(data, '{city}', '"ottawa"') where number = 1;
However, I need a way to add new key-value if it does not exists and update key value if it exists. Is it possible to achieve this in single query?