From e187c2957532b67d5e9dce49a9db670b5c55dd81 Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Tue, 1 Oct 2024 15:10:23 +0000 Subject: [PATCH] Backport #69676 to 24.9: fix bug about `CREATE ... AS WITH RECURSIVE` --- src/Interpreters/AddDefaultDatabaseVisitor.h | 5 ++++- ...237_create_table_select_as_with_recursive.reference | 0 .../03237_create_table_select_as_with_recursive.sql | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/queries/0_stateless/03237_create_table_select_as_with_recursive.reference create mode 100644 tests/queries/0_stateless/03237_create_table_select_as_with_recursive.sql diff --git a/src/Interpreters/AddDefaultDatabaseVisitor.h b/src/Interpreters/AddDefaultDatabaseVisitor.h index d59fd35df77..4aebccbc6dd 100644 --- a/src/Interpreters/AddDefaultDatabaseVisitor.h +++ b/src/Interpreters/AddDefaultDatabaseVisitor.h @@ -121,7 +121,10 @@ private: { if (select.recursive_with) for (const auto & child : select.with()->children) - with_aliases.insert(child->as()->name); + { + if (typeid_cast(child.get())) + with_aliases.insert(child->as()->name); + } if (select.tables()) tryVisit(select.refTables()); diff --git a/tests/queries/0_stateless/03237_create_table_select_as_with_recursive.reference b/tests/queries/0_stateless/03237_create_table_select_as_with_recursive.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/03237_create_table_select_as_with_recursive.sql b/tests/queries/0_stateless/03237_create_table_select_as_with_recursive.sql new file mode 100644 index 00000000000..bd8c19cc408 --- /dev/null +++ b/tests/queries/0_stateless/03237_create_table_select_as_with_recursive.sql @@ -0,0 +1,10 @@ +drop table if exists t; +SET enable_analyzer = 1; +create table t1 (a Int64, s DateTime('Asia/Istanbul')) Engine = MergeTree() ORDER BY a; +create view t AS ( + WITH RECURSIVE 42 as ttt, + toDate(s) as start_date, + _table as (select 1 as number union all select number + 1 from _table where number < 10) + SELECT a, ttt from t1 join _table on t1.a = _table.number and start_date = '2024-09-23' +); +drop table t;