如何更新 jsonb 子元素 postgres?
How to update jsonb sub element postgres?
Table 姓名:the_table
列名:the_column
我想从这里更新:
old_json: {"aa": {"bb": {"asd": "asd", "qqq": "aqaq", "the_key": "the_value"}"}}
修改 json:{"aa": {"bb": {"asd": "asd", "qqq": "aqaq", "the_key": "the_NEW_value"}"}}
在我的例子中,我必须像上面那样更新许多类似的行。
如果我喜欢 update the_table set the_column = jsonb_set(the_column, '{aa}', '"the_value"')
那么结果就像:{"aa": "the_value"}
然后我尝试了 update the_table set the_column = jsonb_set(the_column, '{aa: {bb: {the_key}}}', '"the_value"')
但它不起作用
那么如何正确更新jsonb?
jsonb_set()
的第二个参数是一个文本数组,其中包含作为值路径的键:
UPDATE the_table
SET the_column = jsonb_set(the_column, '{aa, bb, the_key}', '"the_NEW_value"');
Table 姓名:the_table 列名:the_column
我想从这里更新:
old_json: {"aa": {"bb": {"asd": "asd", "qqq": "aqaq", "the_key": "the_value"}"}}
修改 json:{"aa": {"bb": {"asd": "asd", "qqq": "aqaq", "the_key": "the_NEW_value"}"}}
在我的例子中,我必须像上面那样更新许多类似的行。
如果我喜欢 update the_table set the_column = jsonb_set(the_column, '{aa}', '"the_value"')
那么结果就像:{"aa": "the_value"}
然后我尝试了 update the_table set the_column = jsonb_set(the_column, '{aa: {bb: {the_key}}}', '"the_value"')
但它不起作用
那么如何正确更新jsonb?
jsonb_set()
的第二个参数是一个文本数组,其中包含作为值路径的键:
UPDATE the_table
SET the_column = jsonb_set(the_column, '{aa, bb, the_key}', '"the_NEW_value"');