如何更新 postgresql db 中嵌套的 jsonb 属性的值

How to update value of nested jsonb attribute in postgresql db

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

我想将工作单位为管理的记录更新为工作Class A,如下

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

您可以使用jsonb_set()

update the_table
  set the_column = jsonb_set(the_column, '{personalDetails,"Work Class"}', '"A"')
where the_column #>> '{personalDetails,"Working Unit"}' = 'Management';
update table_name 
set column_name = jsonb_set("column_name", '{"personalDetails", "Work Class"}', '"A"'::jsonb) 
where column_name::json->'personalDetail'->>'Working Unit' = 'Management' ;