Skip to content

Commit 08696e6

Browse files
committed
Update MP SELECT Ancestors.md
1 parent c7f041a commit 08696e6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

MP SELECT Ancestors.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ follows the "nested doll" design, with each node name acting as a JSON object ke
5050

5151
~~~sql
5252
WITH
53+
------------------------------ PROLOGUE ------------------------------
5354
json_nodes(ids) AS (
5455
VALUES
5556
('["tcl/compat/zlib1/", "tcl/pkgs/thread2.8.7/tcl/cmdsrv/"]')
@@ -59,6 +60,8 @@ WITH
5960
FROM json_nodes AS jn, json_each(jn.ids) AS node_ids
6061
),
6162
tops AS (SELECT node_id AS path FROM nodes),
63+
/********************************************************************/
64+
--------------------------- ANCESTOR LIST ----------------------------
6265
prefixes AS (
6366
SELECT ascii_id, prefix,
6467
length(prefix) - length(replace(prefix, '/', '')) AS depth
@@ -78,6 +81,7 @@ WITH
7881
json_tree(replace(jp.prefix_json, '.', '^#^')) AS prefixes
7982
WHERE prefixes.parent IS NOT NULL
8083
)
84+
/********************************************************************/
8185
SELECT * FROM ancestors;
8286
~~~
8387

@@ -101,6 +105,7 @@ A similar query splits provided paths directly:
101105

102106
~~~sql
103107
WITH
108+
------------------------------ PROLOGUE ------------------------------
104109
json_nodes(ids) AS (
105110
VALUES
106111
('["tcl/compat/zlib1/", "tcl/pkgs/thread2.8.7/tcl/cmdsrv/"]')
@@ -110,6 +115,8 @@ WITH
110115
FROM json_nodes AS jn, json_each(jn.ids) AS node_ids
111116
),
112117
tops AS (SELECT id, node_id AS path FROM nodes),
118+
/********************************************************************/
119+
--------------------------- ANCESTOR LIST ----------------------------
113120
levels AS (
114121
SELECT id, path, length(path) - length(replace(path, '/', '')) AS depth
115122
FROM tops
@@ -130,6 +137,7 @@ WITH
130137
GROUP BY asc_path
131138
ORDER BY id, asc_path
132139
)
140+
/********************************************************************/
133141
SELECT * FROM ancestors;
134142
~~~
135143

0 commit comments

Comments
 (0)