1

Table name: the_table Column name: the_column

I want to update from this: old_json: {"aa": {"bb": {"asd": "asd", "qqq": "aqaq", "the_key": "the_value"}"}} modified json: {"aa": {"bb": {"asd": "asd", "qqq": "aqaq", "the_key": "the_NEW_value"}"}}

In my case I have to update many similar rows like above. if I do like that update the_table set the_column = jsonb_set(the_column, '{aa}', '"the_value"') then result be like : {"aa": "the_value"}

Then I tried update the_table set the_column = jsonb_set(the_column, '{aa: {bb: {the_key}}}', '"the_value"') but it's does't work

So how to update jsonb correctly?

1 Answer 1

1

demo:db<>fiddle

The second parameter of jsonb_set() is an text array which contains the keys as path to your values:

UPDATE the_table 
SET the_column = jsonb_set(the_column, '{aa, bb, the_key}', '"the_NEW_value"');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.