@@ -50,6 +50,7 @@ follows the "nested doll" design, with each node name acting as a JSON object ke
50
50
51
51
~~~ sql
52
52
WITH
53
+ -- ---------------------------- PROLOGUE ------------------------------
53
54
json_nodes(ids) AS (
54
55
VALUES
55
56
(' ["tcl/compat/zlib1/", "tcl/pkgs/thread2.8.7/tcl/cmdsrv/"]' )
59
60
FROM json_nodes AS jn, json_each(jn .ids ) AS node_ids
60
61
),
61
62
tops AS (SELECT node_id AS path FROM nodes),
63
+ /* *******************************************************************/
64
+ -- ------------------------- ANCESTOR LIST ----------------------------
62
65
prefixes AS (
63
66
SELECT ascii_id, prefix,
64
67
length(prefix) - length(replace(prefix, ' /' , ' ' )) AS depth
78
81
json_tree(replace(jp .prefix_json , ' .' , ' ^#^' )) AS prefixes
79
82
WHERE prefixes .parent IS NOT NULL
80
83
)
84
+ /* *******************************************************************/
81
85
SELECT * FROM ancestors;
82
86
~~~
83
87
@@ -101,6 +105,7 @@ A similar query splits provided paths directly:
101
105
102
106
~~~ sql
103
107
WITH
108
+ -- ---------------------------- PROLOGUE ------------------------------
104
109
json_nodes(ids) AS (
105
110
VALUES
106
111
(' ["tcl/compat/zlib1/", "tcl/pkgs/thread2.8.7/tcl/cmdsrv/"]' )
110
115
FROM json_nodes AS jn, json_each(jn .ids ) AS node_ids
111
116
),
112
117
tops AS (SELECT id, node_id AS path FROM nodes),
118
+ /* *******************************************************************/
119
+ -- ------------------------- ANCESTOR LIST ----------------------------
113
120
levels AS (
114
121
SELECT id, path , length(path ) - length(replace(path , ' /' , ' ' )) AS depth
115
122
FROM tops
130
137
GROUP BY asc_path
131
138
ORDER BY id, asc_path
132
139
)
140
+ /* *******************************************************************/
133
141
SELECT * FROM ancestors;
134
142
~~~
135
143
0 commit comments