首页 > 解决方案 > 更新 JSONb 值

问题描述

我想更新 PostgreSQL 表中的 JSONb 值,这里是他的原型:

{
    key1: {
        key2: {
            key3: value
            ...
        }
        ...
    }
    ...
}

我想更新key1->key2->>key3

标签: postgresqljsonb

解决方案


您可以jsonb_set()为此使用:

update the_table
   set the_column = jsonb_set(the_column, '{key1,key2}', '{"key3": "new_value"}')
where the_pk_column = 42;

在线示例:https ://rextester.com/CEWF51936


推荐阅读