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 COPY Subtrees.md
+17-2Lines changed: 17 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,10 +6,15 @@ parent: Materialized Paths
6
6
permalink: /mat-paths/copy
7
7
---
8
8
9
-
The current convention for the COPY operation is to copy category subtrees only for each input category, but no category-item assignment. This convention simplifies the script
9
+
The current convention for the COPY operation is to copy category subtrees only for each input category, but no category-item assignment. The core transformation step uses an RCTE loop discussed in the [RCTEs for Recursive Modify](../patterns/rcte-modify) section. Because the total number of existing category paths may be substantially higher than the number of affected paths, it is desirable to isolate the subset of affected paths. The *subtrees_old* CTE achieves this goal by matching the category path prefix against the *path_old* variable (*ops*).
10
+
11
+
Postprocessing involves several filtering steps. *LOOP_COPY* transforms the initial path set and labels new rows. The *subtrees_new_base* CTE filters out original paths and some of the possible duplicates among the newly created paths. The second step (*subtrees_path*) filters out all remaining duplicates. The final filtering stage (*subtrees_new*) removes already existing paths.
12
+
13
+
The rest of the code creates the remaining paths (the code is similar to the [CREATE Paths](./create) section).
Copy file name to clipboardExpand all lines: MP MOVE Subtrees.md
+18-2Lines changed: 18 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,20 @@ parent: Materialized Paths
6
6
permalink: /mat-paths/move
7
7
---
8
8
9
+
The MOVE script moves/renames specified categories. The script also needs to handle associated items when necessary. For non-existing new paths, the database updates item associations automatically via foreign key cascades. However, when a collision occurs (existing new path), the scripts keeps one copy only (preferably the existing one), deleting the rest, and must update item associations explicitly before deletion. The current script updates the *files_categories* demo table and needs to be adjusted for actual association tables.
10
+
11
+
The core transformation step uses an RCTE loop discussed in the [RCTEs for Recursive Modify](../patterns/rcte-modify) section. The MOVE operation does not create new paths as opposed to the COPY operation, so the loop code is simplified. Because the total number of existing category paths may be substantially higher than the number of affected paths, it is desirable to isolate the subset of affected paths. The *subtrees_old* CTE achieves this goal by matching the category path prefix against the *path_old* variable (*ops*).
12
+
13
+
Postprocessing code includes two filters. The *subtrees_path* CTE matches the old and new paths and filters out unchanged categories. The *new_paths* CTE labels category rows for which path already exists in the *categories* table or duplicate *path_new* entries are present in the *subtrees_new_base*. The final set is used to update the *categories* table and associated relationship tables.
0 commit comments