From 81f6e993e9723bb89f5ce4b68a5eb61774c4ab76 Mon Sep 17 00:00:00 2001 From: Konstantin Bogdanov Date: Tue, 26 Nov 2024 03:45:15 +0100 Subject: [PATCH] Allow parsing both variants of BACKUP EXCEPT TABLES query --- src/Parsers/ParserBackupQuery.cpp | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) 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;