fix crash in CREATE AS

This commit is contained in:
Alexander Tokmakov 2020-11-16 13:14:12 +03:00
parent 11f56186db
commit 8352e5d202
3 changed files with 24 additions and 1 deletions

View File

@ -630,7 +630,12 @@ void InterpreterCreateQuery::setEngine(ASTCreateQuery & create) const
"Cannot CREATE a table AS " + qualified_name + ", it is a Dictionary",
ErrorCodes::INCORRECT_QUERY);
create.set(create.storage, as_create.storage->ptr());
if (as_create.storage)
create.set(create.storage, as_create.storage->ptr());
else if (as_create.as_table_function)
create.as_table_function = as_create.as_table_function->clone();
else
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot set engine, it's a bug.");
}
}

View File

@ -0,0 +1,4 @@
CREATE TABLE default.table2\n(\n `number` UInt64\n) AS numbers(5)
CREATE TABLE default.table3\n(\n `number` UInt64\n) AS numbers(5)
5 10
5 10

View File

@ -0,0 +1,14 @@
DROP TABLE IF EXISTS table2;
DROP TABLE IF EXISTS table3;
CREATE TABLE table2 AS numbers(5);
CREATE TABLE table3 AS table2;
SHOW CREATE table2;
SHOW CREATE table3;
SELECT count(), sum(number) FROM table2;
SELECT count(), sum(number) FROM table3;
DROP TABLE table2;
DROP TABLE table3;