You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: MP SELECT Ancestors.md
+31-3
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,20 @@ WITH
80
80
SELECT*FROM ancestors;
81
81
~~~
82
82
83
-
Blocks *json_nodes* through *tops* constitute the same prologue as [before](select-desc#prologue). The *prefixes* block retrieves node prefixes from the *categories* table (alternatively, prefixes could be calculated from the input by stripping the last path parts). *json_prefixes* prepares "nested doll" JSON objects, and the *ancestors* block generates ancestor lists. The last block temporarily escapes any periods in names by replacing them with '^#^' at the beginning and performing the inverse replacement at the end.
83
+
Blocks *json_nodes* through *tops* constitute the same prologue as [before](select-desc#prologue). The *prefixes* block retrieves node prefixes from the *categories* table (alternatively, the query could incorporate the [path splitting template](../patterns/split-dsv#Split-Path)). *json_prefixes* prepares "nested doll" JSON objects. The *ancestors* block generates ancestor lists, temporarily replacing any periods in names with '^#^' at the beginning and reversing it at the end. Note that if the input contains multiple paths with a shared prefix, the *asc_path* will have duplicate values.
json_tree(replace(jo.json_obj, '.', '^#^')) AS terms
113
126
WHEREterms.parentIS NOT NULL
127
+
GROUP BY asc_path
128
+
ORDER BY id, asc_path
114
129
)
115
130
SELECT*FROM ancestors;
116
131
~~~
117
132
118
-
This query splits paths as provided and no longer accesses the *categories* table. The _nodes_ block also labels paths with array element id generated by _json_each_ instead of *ascii_id*.
133
+
This query splits paths as provided and no longer accesses the *categories* table. Additionally, the *nodes* block labels paths with array element id (instead of *ascii_id*) generated by *json_each*, and the *ancestors* block removes duplicate terms.
0 commit comments