diff --git a/src/Parsers/ParserBackupQuery.cpp b/src/Parsers/ParserBackupQuery.cpp index 6d2f4d8311d..f6993fdb811 100644 --- a/src/Parsers/ParserBackupQuery.cpp +++ b/src/Parsers/ParserBackupQuery.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -16,6 +17,11 @@ namespace DB { +namespace ErrorCodes +{ + extern const int SYNTAX_ERROR; +} + namespace { using Kind = ASTBackupQuery::Kind; @@ -78,19 +84,20 @@ namespace auto parse_list_element = [&] { DatabaseAndTableName table_name; - if (database_name) - { - ASTPtr ast; - if (!ParserIdentifier{}.parse(pos, ast, expected)) - return false; + + if (!parseDatabaseAndTableName(pos, expected, table_name.first, table_name.second)) + return false; + + if (database_name && table_name.first.empty()) table_name.first = *database_name; - table_name.second = getIdentifierName(ast); - } - else - { - if (!parseDatabaseAndTableName(pos, expected, table_name.first, table_name.second)) - return false; - } + + if (database_name && table_name.first != *database_name) + throw Exception( + ErrorCodes::SYNTAX_ERROR, + "Database name in EXCEPT TABLES clause doesn't match the database name in DATABASE clause: {} != {}", + table_name.first, + *database_name + ); result.emplace(std::move(table_name)); return true;