Skip to content
Advertisement

How to update a specific value of a object present in array of object within Postgres JSON Field

Here is my JSON field value. which is stored in the PostgreSQL table. I want to search and update the specific user_name in the user key

whose name is Devang to Dev using Django JSONField for example

I have tried the RAWQuery for the find. This is the query.

It will return like this

I have also tried JSON_SET to update the user_name but JSON_SET only accepts. It will update the upper level, not a nesting level

Advertisement

Answer

Using JSONB_SETis a bit tricky in case of nested element updation. If you want to set the value of nested element first you need to get the exact path of element to be updated. Please try below query:

DEMO

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement