summaryrefslogtreecommitdiff
path: root/src/test/regress/expected/with.out
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/regress/expected/with.out')
-rw-r--r--src/test/regress/expected/with.out48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/test/regress/expected/with.out b/src/test/regress/expected/with.out
index fe7561065e..e8d3e43b7b 100644
--- a/src/test/regress/expected/with.out
+++ b/src/test/regress/expected/with.out
@@ -452,6 +452,54 @@ SELECT t1.id, count(t2.*) FROM t AS t1 JOIN t AS t2 ON
(2 rows)
--
+-- test cycle detection
+--
+create temp table graph( f int, t int, label text );
+insert into graph values
+ (1, 2, 'arc 1 -> 2'),
+ (1, 3, 'arc 1 -> 3'),
+ (2, 3, 'arc 2 -> 3'),
+ (1, 4, 'arc 1 -> 4'),
+ (4, 5, 'arc 4 -> 5'),
+ (5, 1, 'arc 5 -> 1');
+with recursive search_graph(f, t, label, path, cycle) as (
+ select *, array[row(g.f, g.t)], false from graph g
+ union all
+ select g.*, path || array[row(g.f, g.t)], row(g.f, g.t) = any(path)
+ from graph g, search_graph sg
+ where g.f = sg.t and not cycle
+)
+select * from search_graph;
+ f | t | label | path | cycle
+---+---+------------+-------------------------------------------+-------
+ 1 | 2 | arc 1 -> 2 | {"(1,2)"} | f
+ 1 | 3 | arc 1 -> 3 | {"(1,3)"} | f
+ 2 | 3 | arc 2 -> 3 | {"(2,3)"} | f
+ 1 | 4 | arc 1 -> 4 | {"(1,4)"} | f
+ 4 | 5 | arc 4 -> 5 | {"(4,5)"} | f
+ 5 | 1 | arc 5 -> 1 | {"(5,1)"} | f
+ 1 | 2 | arc 1 -> 2 | {"(5,1)","(1,2)"} | f
+ 1 | 3 | arc 1 -> 3 | {"(5,1)","(1,3)"} | f
+ 1 | 4 | arc 1 -> 4 | {"(5,1)","(1,4)"} | f
+ 2 | 3 | arc 2 -> 3 | {"(1,2)","(2,3)"} | f
+ 4 | 5 | arc 4 -> 5 | {"(1,4)","(4,5)"} | f
+ 5 | 1 | arc 5 -> 1 | {"(4,5)","(5,1)"} | f
+ 1 | 2 | arc 1 -> 2 | {"(4,5)","(5,1)","(1,2)"} | f
+ 1 | 3 | arc 1 -> 3 | {"(4,5)","(5,1)","(1,3)"} | f
+ 1 | 4 | arc 1 -> 4 | {"(4,5)","(5,1)","(1,4)"} | f
+ 2 | 3 | arc 2 -> 3 | {"(5,1)","(1,2)","(2,3)"} | f
+ 4 | 5 | arc 4 -> 5 | {"(5,1)","(1,4)","(4,5)"} | f
+ 5 | 1 | arc 5 -> 1 | {"(1,4)","(4,5)","(5,1)"} | f
+ 1 | 2 | arc 1 -> 2 | {"(1,4)","(4,5)","(5,1)","(1,2)"} | f
+ 1 | 3 | arc 1 -> 3 | {"(1,4)","(4,5)","(5,1)","(1,3)"} | f
+ 1 | 4 | arc 1 -> 4 | {"(1,4)","(4,5)","(5,1)","(1,4)"} | t
+ 2 | 3 | arc 2 -> 3 | {"(4,5)","(5,1)","(1,2)","(2,3)"} | f
+ 4 | 5 | arc 4 -> 5 | {"(4,5)","(5,1)","(1,4)","(4,5)"} | t
+ 5 | 1 | arc 5 -> 1 | {"(5,1)","(1,4)","(4,5)","(5,1)"} | t
+ 2 | 3 | arc 2 -> 3 | {"(1,4)","(4,5)","(5,1)","(1,2)","(2,3)"} | f
+(25 rows)
+
+--
-- test multiple WITH queries
--
WITH RECURSIVE