add current database to a CREATE SELECT query only for views [#CLICKHOUSE-3448]

This commit is contained in:
Alexey Zatelepin 2017-11-21 16:30:45 +03:00 committed by alexey-milovidov
parent e448f4a73a
commit b2963d4c60

View File

@ -483,12 +483,13 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
if (create.to_database.empty())
create.to_database = current_database;
if (create.select && (create.is_view || create.is_materialized_view))
create.select->setDatabaseIfNeeded(current_database);
std::unique_ptr<InterpreterSelectQuery> interpreter_select;
Block as_select_sample;
/// For `view` type tables, you may need `sample_block` to get the columns.
if (create.select && (!create.attach || (!create.columns && (create.is_view || create.is_materialized_view))))
if (create.select && (!create.attach || !create.columns))
{
create.select->setDatabaseIfNeeded(current_database);
interpreter_select = std::make_unique<InterpreterSelectQuery>(create.select->clone(), context);
as_select_sample = interpreter_select->getSampleBlock();
}
@ -549,8 +550,9 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create)
res->startup();
/// If the CREATE SELECT query is, insert the data into the table
if (create.select && !create.is_view && (!create.is_materialized_view || create.is_populate))
/// If the query is a CREATE SELECT, insert the data into the table.
if (create.select && !create.attach
&& !create.is_view && (!create.is_materialized_view || create.is_populate))
{
auto table_lock = res->lockStructure(true, __PRETTY_FUNCTION__);