简体   繁体   English

在 postgres 中更新 jsonb 对象

[英]Update jsonb object in postgres

One of my column is jsonb and have value in the format.我的专栏之一是 jsonb 并且具有格式价值。 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".我想更新campaign_info(列名)列的内部键“已处理”和“模型”的campaign_id 是“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' .这将使用值'completed'更新路径"876" > "processed"的值。

In your update query:在您的更新查询中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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