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
### Scope of provided selection queries for the MPs model
10
10
11
-
This and the following sections provide a family of standard MPs queries for selecting a set of category tree nodes, their descendants, and ancestors. These queries return rows from the *categories* table for the following standard MPs node sets:
11
+
Current and the following sections provide a family of standard MPs queries for selecting a set of category tree nodes, their descendants, and ancestors. These queries return rows from the *categories* table for the following standard MPs node sets:
12
12
13
13
- root nodes (just the nodes from the input)
14
-
- all descendants, excluding the root nodes
15
14
- subtrees, including root nodes and descendants
15
+
- all descendants, excluding the root nodes
16
16
- children, i.e., direct descendants only
17
17
18
18
All provided selection queries have the [modular CTEs-based](../meta/db-derived-cte) structure and take a unified input in the form of a [JSON-array-formatted](../patterns/json-sql-input) string
@@ -25,7 +25,7 @@ with a list of category *path* values, identifying subtree root nodes.
25
25
26
26
### Query structure and alternative category identifiers
27
27
28
-
Each query starts with a prologue. Its function is to take the unified JSON array string of category identifiers (the *json_nodes* entry block) and its exit *tops* block produces a table containing the *path* column with one category path per row:
28
+
Each query starts with a prologue. Its function is to take a unified JSON array string with category identifiers (the *json_nodes* entry block), and its exit *tops* block produces a table containing the *path* column with one category path per row:
29
29
30
30
#### Prologue input
31
31
@@ -58,15 +58,15 @@ SELECT * FROM tops ORDER BY path;
58
58
59
59
---
60
60
61
-
Query prologue decouples the input format details from the query business logic. With query prologue and its output format defined, the input format and query business logic can be modified indepently. For example, switching from path-based to ascii_id-based identifies requires a localized change to a single block *tops*, identical for all queries in this family (immediate input in *json_nodes* is also adjusted; in production, a query parameter replaces this string input):
61
+
The query prologue decouples the input format details from the query business logic, permitting their independent modification. For example, switching from path-based to ascii_id-based identifies requires a localized change to a single block *tops*, identical for all queries in this family (immediate input in *json_nodes* is also adjusted; in production, a query parameter replaces this string input):
62
62
63
-
#### Input
63
+
#### Input - *ascii_id*
64
64
65
65
~~~json
66
66
["0FDAF2C8","65887f45"]
67
67
~~~
68
68
69
-
#### Prologue
69
+
#### Prologue - *ascii_id*
70
70
71
71
~~~sql
72
72
WITH
@@ -78,19 +78,40 @@ WITH
78
78
SELECTnode_ids.valueAS node_id
79
79
FROM json_nodes AS jn, json_each(jn.ids) AS node_ids
80
80
),
81
-
tops AS (
82
-
SELECTcats.path
83
-
FROM categories AS cats, nodes
84
-
WHEREcats.ascii_idIN (nodes.node_id)
85
-
)
81
+
tops AS (SELECTpathFROM categories WHERE ascii_id IN nodes)
86
82
SELECT*FROM tops ORDER BYpath;
87
83
~~~
88
84
89
85
---
90
86
91
-
### MPs queries
87
+
### Selection queries
88
+
89
+
The following query selects just the nodes from the input (root nodes).
FROM json_nodes AS jn, json_each(jn.ids) AS node_ids
100
+
),
101
+
tops AS (SELECT node_id ASpathFROM nodes),
102
+
records AS (SELECT*FROM categories WHEREpathIN nodes)
103
+
SELECT*FROM records ORDER BYpath;
104
+
~~~
105
+
106
+
The remaining three queries in this section have almost identical code, with the only difference in the WHERE clause (*records*). In the query template below, replace %SELECTOR% according to the following table:
92
107
93
-
Note that the four queries have alomst identical code, with the only difference in the WHERE clause (*records*). Here is a query template:
0 commit comments