Fix CTE in INSERT-SELECT

This commit is contained in:
Amos Bird 2021-02-09 00:25:24 +08:00
parent be27578294
commit 46f2b4063f
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
4 changed files with 5 additions and 1 deletions

View File

@ -294,7 +294,7 @@ InterpreterSelectQuery::InterpreterSelectQuery(
}
// Only propagate WITH elements to subqueries if we're not a subquery
if (options.subquery_depth == 0)
if (!options.is_subquery)
{
if (context->getSettingsRef().enable_global_with_statement)
ApplyWithAliasVisitor().visit(query_ptr);

View File

@ -33,6 +33,7 @@ struct SelectQueryOptions
bool ignore_quota = false;
bool ignore_limits = false;
bool is_internal = false;
bool is_subquery = false; // non-subquery can also have subquery_depth > 0, e.g. insert select
SelectQueryOptions(QueryProcessingStage::Enum stage = QueryProcessingStage::Complete, size_t depth = 0)
: to_stage(stage), subquery_depth(depth)
@ -46,6 +47,7 @@ struct SelectQueryOptions
SelectQueryOptions out = *this;
out.to_stage = QueryProcessingStage::Complete;
++out.subquery_depth;
out.is_subquery = true;
return out;
}

View File

@ -0,0 +1,2 @@
create or replace table t engine = Memory as with cte as (select * from numbers(10)) select * from cte;
drop table t;