mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-01 20:12:02 +00:00
prevent normalization of WITH RECURSIVE alias
This commit is contained in:
parent
f947f91b10
commit
d83c0c1b3b
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Common/typeid_cast.h>
|
||||
#include <Parsers/ASTWithElement.h>
|
||||
#include <Parsers/ASTLiteral.h>
|
||||
#include <Parsers/ASTQueryWithTableAndOutput.h>
|
||||
#include <Parsers/ASTRenameQuery.h>
|
||||
@ -100,6 +101,7 @@ private:
|
||||
|
||||
const String database_name;
|
||||
std::set<String> external_tables;
|
||||
mutable String with_alias;
|
||||
|
||||
bool only_replace_current_database_function = false;
|
||||
bool only_replace_in_join = false;
|
||||
@ -117,6 +119,9 @@ private:
|
||||
|
||||
void visit(ASTSelectQuery & select, ASTPtr &) const
|
||||
{
|
||||
if (auto with = select.with())
|
||||
with_alias = with->children[0]->as<ASTWithElement>()->name;
|
||||
|
||||
if (select.tables())
|
||||
tryVisit<ASTTablesInSelectQuery>(select.refTables());
|
||||
|
||||
@ -165,6 +170,9 @@ private:
|
||||
/// There is temporary table with such name, should not be rewritten.
|
||||
if (external_tables.contains(identifier.shortName()))
|
||||
return;
|
||||
/// This is WITH RECURSIVE alias.
|
||||
if (identifier.name() == with_alias)
|
||||
return;
|
||||
|
||||
auto qualified_identifier = std::make_shared<ASTTableIdentifier>(database_name, identifier.name());
|
||||
if (!identifier.alias.empty())
|
||||
|
@ -0,0 +1 @@
|
||||
5050
|
13
tests/queries/0_stateless/03215_view_with_recursive.sql
Normal file
13
tests/queries/0_stateless/03215_view_with_recursive.sql
Normal file
@ -0,0 +1,13 @@
|
||||
CREATE VIEW 03215_test_v
|
||||
AS WITH RECURSIVE test_table AS
|
||||
(
|
||||
SELECT 1 AS number
|
||||
UNION ALL
|
||||
SELECT number + 1
|
||||
FROM test_table
|
||||
WHERE number < 100
|
||||
)
|
||||
SELECT sum(number)
|
||||
FROM test_table;
|
||||
|
||||
SELECT * FROM 03215_test_v;
|
Loading…
Reference in New Issue
Block a user