Merge pull request #58841 from yariks5s/dictionary_table_exception_fix

Fixing exceptions when table/dictionary already exist
This commit is contained in:
Yarik Briukhovetskyi 2024-01-29 22:41:06 +01:00 committed by GitHub
commit 5ba82eed81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View File

@ -1435,8 +1435,14 @@ bool InterpreterCreateQuery::doCreateTable(ASTCreateQuery & create,
interpreter.execute(); interpreter.execute();
} }
else else
throw Exception(storage_already_exists_error_code, {
"{} {}.{} already exists", storage_name, backQuoteIfNeed(create.getDatabase()), backQuoteIfNeed(create.getTable())); if (database->getTable(create.getTable(), getContext())->isDictionary())
throw Exception(ErrorCodes::DICTIONARY_ALREADY_EXISTS,
"Dictionary {}.{} already exists", backQuoteIfNeed(create.getDatabase()), backQuoteIfNeed(create.getTable()));
else
throw Exception(ErrorCodes::TABLE_ALREADY_EXISTS,
"Table {}.{} already exists", backQuoteIfNeed(create.getDatabase()), backQuoteIfNeed(create.getTable()));
}
} }
else if (!create.attach) else if (!create.attach)
{ {

View File

@ -0,0 +1,6 @@
CREATE TABLE test_table (i Int64) engine=MergeTree order by i;
CREATE DICTIONARY test_dict (y String, value UInt64 DEFAULT 0) PRIMARY KEY y SOURCE(CLICKHOUSE(TABLE 'test_table')) LAYOUT(DIRECT());
CREATE TABLE test_dict (y Int64) engine=MergeTree order by y; -- { serverError DICTIONARY_ALREADY_EXISTS }
CREATE DICTIONARY test_table (y String, value UInt64 DEFAULT 0) PRIMARY KEY y SOURCE(CLICKHOUSE(TABLE 'test_table')) LAYOUT(DIRECT()); -- { serverError TABLE_ALREADY_EXISTS }
CREATE DICTIONARY test_dict (y String, value UInt64 DEFAULT 0) PRIMARY KEY y SOURCE(CLICKHOUSE(TABLE 'test_table')) LAYOUT(DIRECT()); -- { serverError DICTIONARY_ALREADY_EXISTS }
CREATE TABLE test_table (y Int64) engine=MergeTree order by y; -- { serverError TABLE_ALREADY_EXISTS }