diff --git a/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp b/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp index 944675f860e..b4ecf3b83a4 100644 --- a/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp +++ b/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp @@ -99,6 +99,13 @@ std::unordered_set DatabasePostgreSQL::fetchTablesList() const bool DatabasePostgreSQL::checkPostgresTable(const String & table_name) const { + if (table_name.find('\'') != std::string::npos + || table_name.find('\\') != std::string::npos) + { + throw Exception(ErrorCodes::BAD_ARGUMENTS, + "PostgreSQL table name cannot contain single quote or backslash characters, passed {}", table_name); + } + pqxx::nontransaction tx(*connection->conn()); try