Skip to content

Commit c625554

Browse files
committed
Update Patterns RCTEs Modify.md
1 parent e3a1717 commit c625554

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Patterns RCTEs Modify.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ WITH RECURSIVE
4242
WHERE ops.opid = BUFFER.opid + 1
4343
AND BUFFER.path_new like rootpath_old || '%'
4444
)
45-
SELECT * FROM LOOP_COPY;
45+
SELECT * FROM LOOP_COPY
46+
WHERE opid = (SELECT max(ops.opid) FROM ops);
4647
~~~
4748

48-
Note that this task is still not particularly well suited for SQL. The initial SELECT places all paths in the processing queue, making them available in the first loop cycle. Because the COPY operation does not delete any folders, the entire input must be placed in the processing queue for the next loop cycle, meaning that the initial set and all previously created paths are duplicated during each loop cycle.
49+
Note that this task is still not particularly well suited for SQL. The initial SELECT places all paths in the processing queue for the first loop cycle. Because the COPY operation does not delete any folders, the entire input must be passed along between loop cycles, meaning that the initial set and all previously created paths are duplicated during each loop cycle. For this reason, the entire row set corresponding to the processing of the last operation is the final result, hence the last line in the query.
4950

5051
Even though the RCTE loop body processes one row at a time, when the processing queue acts as FIFO (the default behavior), it might be helpful to treat the RCTE loop as if it processed the entire row set produced by the preceding cycle. When the processing queue acts as FIFO, this treatment is appropriate, as illustrated by the two tables above (compare the output of *Loop Cycle #1* shown in the first table with the column *Cycle #3* from the second table). The query below shows an equivalent implementation of the RCTE block (only valid for the given input), which unravels the above *LOOP_COPY* RCTE.
5152

0 commit comments

Comments
 (0)