【发布时间】:2020-03-21 07:19:57
【问题描述】:
我的json是
[
{
"id": null,
"st": "value1",
"key": 1,
"value": "i am calling from",
"description": null
},
{
"st": "value2",
"key": 5,
"value": "i am calling from",
"description": null
},
{
"id": 25,
"st": "value3",
"key": 1,
"value": "i am calling from",
"description": null
}
]
我需要用一个数字迭代 id(仅当它为 null 且没有 id 键时)并形成与下面相同的 json,即使缺少键 (id) 也是如此。它必须是自动 id 生成,因为我永远不知道这个聚合中有多少元素。
[
{
"id": 1,
"st": "value1",
"key": 1,
"value": "i am calling from",
"description": null
},
{
"id": 2,
"st": "value2",
"key": 5,
"value": "i am calling from",
"description": null
},
{
"id": 25,
"st": "value3",
"key": 1,
"value": "i am calling from",
"description": null
}
]
我相信 RECURSIVE CTE 有效,但我无法找到解决此问题的方法。请帮忙
【问题讨论】:
标签: json common-table-expression postgresql-11 postgresql-12