简体   繁体   中英

Update jsonb object in postgres

One of my column is jsonb and have value in the format. The value of a single row of column is below.

{
    "835": {
        "cost": 0, 
        "name": "FACEBOOK_FB1_6JAN2020", 
        "email": "test.user@silverpush.co", 
        "views": 0, 
        "clicks": 0, 
        "impressions": 0, 
        "campaign_state": "paused", 
        "processed":"in_progress", 
        "modes":["obj1","obj2"]
    }, 
    "876": {
        "cost": 0, 
        "name": "MARVEL_BLACK_WIDOW_4DEC2019", 
        "email": "test.user@silverpush.co", 
        "views": 0, 
        "clicks": 0, 
        "impressions": 0, 
        "campaign_state": "paused", 
        "processed":"in_progress", 
        "modes":["obj1","obj2"]
    }
}

I want to update campaign_info(column name) column's the inner key "processed" and "models" of the campaign_id is "876".

I have tried this query:

update safe_vid_info 
set campaign_info -> '835' --> 'processed'='completed' 
where cid = 'kiywgh'; 

But it didn't work.

Any help is appreciated. Thanks.

Is this what you want?

jsonb_set(campaign_info, '{876,processed}', '"completed"')

This updates the value at path "876" > "processed" with value 'completed' .

In your update query:

update safe_vid_info 
set campaign_info = jsonb_set(campaign_info, '{876,processed}', '"completed"')
where cid = 'kiywgh'; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM