小编Ble*_*der的帖子

如何将一组扁平树变成一棵具有多个叶子的树?

我们有这个漂亮的 Postgres 树生成器。然而,它会产生一棵树的切口,而不是一次产生整棵树:

item_id jsonb_pretty
1   {
    "title": "PARENT",
    "item_id": 1,
    "children": {
        "title": "LEVEL 2",
        "item_id": 2,
        "children": {
            "title": "LEVEL 3.2",
            "item_id": 6
        }
    }
}
1   {
    "title": "PARENT",
    "item_id": 1,
    "children": {
        "title": "LEVEL 2",
        "item_id": 2,
        "children": {
            "title": "LEVEL 3.1",
            "item_id": 3,
            "children": {
                "title": "LEVEL 4.1",
                "item_id": 4
            }
        }
    }
}
1   {
    "title": "PARENT",
    "item_id": 1,
    "children": {
        "title": "LEVEL 2",
        "item_id": 2,
        "children": {
            "title": "LEVEL 3.1",
            "item_id": …
Run Code Online (Sandbox Code Playgroud)

postgresql tree cte json recursive

5
推荐指数
1
解决办法
1478
查看次数

标签 统计

cte ×1

json ×1

postgresql ×1

recursive ×1

tree ×1