Postgresql Postgres jsonb_设置多个嵌套字段

Postgresql Postgres jsonb_设置多个嵌套字段,postgresql,jsonb,Postgresql,Jsonb,我有一个DB表,它有一个jsonb列,该列有一个实体和嵌套的子实体。假设我们有: 选择jsonb_集('{“top”:{“nested”:{“leaf”:1}}}','{top,nested,leaf}','2') 通过将top.nested.leaf更新为2,这项工作就可以了 但是,如果我们想处理多个字段,例如: 选择jsonb_集(“{”顶部“:{”嵌套“:{”叶:1},“其他_嵌套“:{”纸张:0}}},“[{顶部,嵌套,叶},{顶部,其他_嵌套,纸张}]”,“[2,2]”) 上述情况不起

我有一个DB表,它有一个jsonb列,该列有一个实体和嵌套的子实体。假设我们有:

选择jsonb_集('{“top”:{“nested”:{“leaf”:1}}}','{top,nested,leaf}','2')

通过将
top.nested.leaf
更新为2,这项工作就可以了

但是,如果我们想处理多个字段,例如:

选择jsonb_集(“{”顶部“:{”嵌套“:{”叶:1},“其他_嵌套“:{”纸张:0}}},“[{顶部,嵌套,叶},{顶部,其他_嵌套,纸张}]”,“[2,2]”)

上述情况不起作用,说明:

错误:数组文字格式错误:[{top,nested,leaf},{top,other_nested,paper}]
第1行:“…”:{“叶”:1},“其他嵌套”:{“纸”:0}}},“[{top,nes…”。。。
^
详细信息:“[”必须引入明确指定的数组维度。

有什么想法吗?

路径和新值都不能有多个值。为了得到想要的结果,必须运行它两次,例如:

SELECT jsonb_set(
  '{"top": {"nested": {"leaf" : 1}, "other_nested": {"paper": 0}}}'
, '{top,nested,leaf}'
, '2'
);
SELECT jsonb_set(
  '{"top": {"nested": {"leaf" : 1}, "other_nested": {"paper": 0}}}'
, '{top,other_nested,paper}'
, '2'
);

我还尝试了以下方法:
createtablettest(datajsonb);插入测试(data)值({“top”:{“nested”:{“leaf”:1,“paper”:10},“other_nested”:{“paper”:0,“leaf”:0}}}}::jsonb);更新测试集数据=数据{“top”:{“nested leaf”:2},“other_nested”:{“paper”:2}}“;通过使用连接从测试中选择数据;
,这也不起作用。根据我对开始问题的评论,有没有一种方法可以通过连接来实现这一点?如果您想在一个语句中使用它,最好尝试
jsonb_集(jsonb_集())
在jsonb|U集合或
|
连接通过将一组字段及其新对象/值传入而建立的实现中需要此功能。
SELECT jsonb_set(
  '{"top": {"nested": {"leaf" : 1}, "other_nested": {"paper": 0}}}'
, '{top,nested,leaf}'
, '2'
);
SELECT jsonb_set(
  '{"top": {"nested": {"leaf" : 1}, "other_nested": {"paper": 0}}}'
, '{top,other_nested,paper}'
, '2'
);