Skip to content

Commit 0e54eef

Browse files
author
Maksim Milyutin
committed
Add test case for recursive CTE
1 parent f8726be commit 0e54eef

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

expected/pathman_basic.out

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,35 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2
20012001
Filter: (c1 < 2500)
20022002
(12 rows)
20032003

2004+
/* Test recursive CTE */
2005+
create table test.recursive_cte_test_tbl(id int not null, name text not null);
2006+
select * from create_hash_partitions('test.recursive_cte_test_tbl', 'id', 2);
2007+
create_hash_partitions
2008+
------------------------
2009+
2
2010+
(1 row)
2011+
2012+
insert into test.recursive_cte_test_tbl (id, name) select id, 'name'||id from generate_series(1,100) f(id);
2013+
insert into test.recursive_cte_test_tbl (id, name) select id, 'name'||(id + 1) from generate_series(1,100) f(id);
2014+
insert into test.recursive_cte_test_tbl (id, name) select id, 'name'||(id + 2) from generate_series(1,100) f(id);
2015+
select * from test.recursive_cte_test_tbl where id = 5;
2016+
id | name
2017+
----+-------
2018+
5 | name5
2019+
5 | name6
2020+
5 | name7
2021+
(3 rows)
2022+
2023+
with recursive test as (select min(name) as name from test.recursive_cte_test_tbl where id = 5 union all select (select min(name) from test.recursive_cte_test_tbl where id = 5 and name > test.name) from test where name is not null) select * from test;
2024+
name
2025+
-------
2026+
name5
2027+
name6
2028+
name7
2029+
2030+
(4 rows)
2031+
20042032
DROP SCHEMA test CASCADE;
2005-
NOTICE: drop cascades to 48 other objects
2033+
NOTICE: drop cascades to 51 other objects
20062034
DROP EXTENSION pg_pathman CASCADE;
20072035
DROP SCHEMA pathman CASCADE;

sql/pathman_basic.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ SELECT set_enable_parent('test.index_on_childs', true);
517517
VACUUM ANALYZE test.index_on_childs;
518518
EXPLAIN (COSTS OFF) SELECT * FROM test.index_on_childs WHERE c1 > 100 AND c1 < 2500 AND c2 = 500;
519519

520+
/* Test recursive CTE */
521+
create table test.recursive_cte_test_tbl(id int not null, name text not null);
522+
select * from create_hash_partitions('test.recursive_cte_test_tbl', 'id', 2);
523+
insert into test.recursive_cte_test_tbl (id, name) select id, 'name'||id from generate_series(1,100) f(id);
524+
insert into test.recursive_cte_test_tbl (id, name) select id, 'name'||(id + 1) from generate_series(1,100) f(id);
525+
insert into test.recursive_cte_test_tbl (id, name) select id, 'name'||(id + 2) from generate_series(1,100) f(id);
526+
select * from test.recursive_cte_test_tbl where id = 5;
527+
with recursive test as (select min(name) as name from test.recursive_cte_test_tbl where id = 5 union all select (select min(name) from test.recursive_cte_test_tbl where id = 5 and name > test.name) from test where name is not null) select * from test;
528+
520529
DROP SCHEMA test CASCADE;
521530
DROP EXTENSION pg_pathman CASCADE;
522531
DROP SCHEMA pathman CASCADE;

0 commit comments

Comments
 (0)