postgresql update json field key value 1

postgresql update json field key value

UPDATE table_name SET attrs = jsonb_set(cast(attrs as jsonb), '{key}', '"new_value"', true) WHERE id = 'some_id'; 

Here is what the above code is Doing:
1. Cast the attrs column to jsonb
2. Set the value of the key to the new value
3. Cast the jsonb back to json
4. Update the row

Similar Posts