Skip to content

Commit c1bde8a

Browse files
committed
COPY/MOVE
1 parent 410a064 commit c1bde8a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

MP COPY Subtrees.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ parent: Materialized Paths
66
permalink: /mat-paths/copy
77
---
88

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
10+
911
~~~sql
1012
WITH RECURSIVE
1113
json_ops(ops) AS (
@@ -40,8 +42,8 @@ WITH RECURSIVE
4042
subtrees_old AS (
4143
SELECT opid, ascii_id, path AS path_old
4244
FROM base_ops, categories
43-
WHERE path like rootpath_old || '%'
44-
ORDER BY opid, path
45+
WHERE path_old like rootpath_old || '%'
46+
ORDER BY opid, path_old
4547
),
4648
LOOP_COPY AS (
4749
SELECT 0 AS opid, ascii_id, path_old AS path_new

MP MOVE Subtrees.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ WITH RECURSIVE
4545
subtrees_old AS (
4646
SELECT opid, ascii_id, path AS path_old
4747
FROM base_ops, categories
48-
WHERE path like rootpath_old || '%'
48+
WHERE path_old like rootpath_old || '%'
4949
ORDER BY opid, path_old
5050
),
5151
LOOP_MOVE AS (
@@ -60,9 +60,8 @@ WITH RECURSIVE
6060
WHERE ops.opid = BUFFER.opid + 1
6161
),
6262
subtrees_new_base AS (
63-
SELECT
64-
ascii_id, path_new,
65-
json_extract('["' || replace(trim(path_new, '/'), '/', '", "') || '"]', '$[#-1]') AS name_new
63+
SELECT ascii_id, path_new,
64+
json_extract('["' || replace(trim(path_new, '/'), '/', '", "') || '"]', '$[#-1]') AS name_new
6665
FROM LOOP_MOVE
6766
WHERE opid = (SELECT max(base_ops.opid) FROM base_ops)
6867
),
@@ -84,7 +83,6 @@ WITH RECURSIVE
8483
INSERT INTO temp.move_targets (ascii_id, path_old, path_new, prefix_new, name_new, target_exists)
8584
SELECT * FROM new_paths ORDER BY target_exists, path_old;
8685

87-
8886
PRAGMA defer_foreign_keys = 1;
8987
SAVEPOINT "MOVE_CATS";
9088

0 commit comments

Comments
 (0)