By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE
CREATE TABLE
INSERT 0 6
INSERT 0 5
CREATE FUNCTION
| tree |
|---|
| { "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 }, { "title": "LEVEL 4.2", "item_id": 5 } ] }, { "title": "LEVEL 3.2", "item_id": 6 } ] } ] } |
SELECT 1
| tree |
|---|
| { "title": "PARENT", "item_id": 1, "children": [ { "title": "LEVEL 2", "item_id": 2, "children": [ { "title": "LEVEL 3.1", "item_id": 3, "children": "2 - stopped recursion at max level" }, { "title": "LEVEL 3.2", "item_id": 6 } ] } ] } |
SELECT 1
| item_id | tree |
|---|---|
| 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 }, { "title": "LEVEL 4.2", "item_id": 5 } ] }, { "title": "LEVEL 3.2", "item_id": 6 } ] } ] } |
SELECT 1