如何更新postgresql数据库中嵌套jsonb属性的值

8hhllhi2  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(604)
{
"personalDetails": {
    "First Name": "Paul", 
    "Last Name": "Jamessen", 
    "Work Class": "A+", 
    "Working Unit": "Management", 
    "email": "demo@demo.com"
    }
}

我想把工作单位是管理层的记录更新到a级,如下所示

{
"personalDetails": {
    "First Name": "Paul", 
    "Last Name": "Jamessen", 
    "Work Class": "A", 
    "Working Unit": "Management", 
    "email": "demo@demo.com"
    }
}
xxe27gdn

xxe27gdn1#

你可以用 jsonb_set() ```
update the_table
set the_column = jsonb_set(the_column, '{personalDetails,"Work Class"}', '"A"')
where the_column #>> '{personalDetails,"Working Unit"}' = 'Management';

相关问题