diff --git a/src/DataStreams/PostgreSQLBlockInputStream.cpp b/src/DataStreams/PostgreSQLBlockInputStream.cpp index 4d9a142da3d..da6a83fb930 100644 --- a/src/DataStreams/PostgreSQLBlockInputStream.cpp +++ b/src/DataStreams/PostgreSQLBlockInputStream.cpp @@ -18,6 +18,7 @@ #include #include + namespace DB { @@ -26,7 +27,6 @@ namespace ErrorCodes extern const int BAD_ARGUMENTS; } - PostgreSQLBlockInputStream::PostgreSQLBlockInputStream( ConnectionPtr connection_, const std::string & query_str_, diff --git a/src/DataStreams/PostgreSQLBlockInputStream.h b/src/DataStreams/PostgreSQLBlockInputStream.h index 431af203caf..b88c81cca0a 100644 --- a/src/DataStreams/PostgreSQLBlockInputStream.h +++ b/src/DataStreams/PostgreSQLBlockInputStream.h @@ -11,6 +11,7 @@ #include #include + namespace DB { using ConnectionPtr = std::shared_ptr; diff --git a/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp b/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp index 1ce82ec36b2..d3ee726b84e 100644 --- a/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp +++ b/src/Databases/PostgreSQL/DatabasePostgreSQL.cpp @@ -101,7 +101,12 @@ bool DatabasePostgreSQL::checkPostgresTable(const String & table_name) const try { - pqxx::result result = tx.exec(fmt::format("select '{}'::regclass", table_name)); + /// Casting table_name::regclass throws pqxx::indefined_table exception if table_name is incorrect. + pqxx::result result = tx.exec(fmt::format( + "SELECT '{}'::regclass, tablename " + "FROM pg_catalog.pg_tables " + "WHERE schemaname != 'pg_catalog' AND schemaname != 'information_schema' " + "AND tablename = '{}'", table_name, table_name)); } catch (pqxx::undefined_table const &) { diff --git a/src/Databases/PostgreSQL/DatabasePostgreSQL.h b/src/Databases/PostgreSQL/DatabasePostgreSQL.h index 68c78b74ba4..950481cb292 100644 --- a/src/Databases/PostgreSQL/DatabasePostgreSQL.h +++ b/src/Databases/PostgreSQL/DatabasePostgreSQL.h @@ -11,6 +11,7 @@ #include #include + namespace DB { diff --git a/src/Databases/PostgreSQL/FetchFromPostgreSQL.cpp b/src/Databases/PostgreSQL/FetchFromPostgreSQL.cpp index c3a8c6ba2ef..b07c71d33a7 100644 --- a/src/Databases/PostgreSQL/FetchFromPostgreSQL.cpp +++ b/src/Databases/PostgreSQL/FetchFromPostgreSQL.cpp @@ -14,6 +14,7 @@ #include #include + namespace DB { @@ -57,6 +58,11 @@ std::shared_ptr fetchPostgreSQLTableStructure(ConnectionPtr c "PostgreSQL table {}.{} does not exist", connection->dbname(), postgres_table_name), ErrorCodes::UNKNOWN_TABLE); } + catch (Exception & e) + { + e.addMessage("while fetching postgresql table structure"); + throw; + } if (columns.empty()) return nullptr; diff --git a/src/Databases/PostgreSQL/FetchFromPostgreSQL.h b/src/Databases/PostgreSQL/FetchFromPostgreSQL.h index bb6b8d46c84..b0b103251a0 100644 --- a/src/Databases/PostgreSQL/FetchFromPostgreSQL.h +++ b/src/Databases/PostgreSQL/FetchFromPostgreSQL.h @@ -7,6 +7,7 @@ #if USE_LIBPQXX #include + namespace DB { diff --git a/src/Dictionaries/PostgreSQLDictionarySource.cpp b/src/Dictionaries/PostgreSQLDictionarySource.cpp index 417ef9b318d..67e959c34b0 100644 --- a/src/Dictionaries/PostgreSQLDictionarySource.cpp +++ b/src/Dictionaries/PostgreSQLDictionarySource.cpp @@ -11,6 +11,7 @@ #include "readInvalidateQuery.h" #endif + namespace DB { diff --git a/src/Dictionaries/PostgreSQLDictionarySource.h b/src/Dictionaries/PostgreSQLDictionarySource.h index eaec84bfee1..a826ff15f4f 100644 --- a/src/Dictionaries/PostgreSQLDictionarySource.h +++ b/src/Dictionaries/PostgreSQLDictionarySource.h @@ -14,6 +14,7 @@ #include #include + namespace DB { diff --git a/src/Storages/StoragePostgreSQL.cpp b/src/Storages/StoragePostgreSQL.cpp index ea1279bc319..c45336d1515 100644 --- a/src/Storages/StoragePostgreSQL.cpp +++ b/src/Storages/StoragePostgreSQL.cpp @@ -157,8 +157,10 @@ public: void writeSuffix() override { if (stream_inserter) + { stream_inserter->complete(); - work->commit(); + work->commit(); + } } diff --git a/src/Storages/StoragePostgreSQL.h b/src/Storages/StoragePostgreSQL.h index 6d1764b2080..684c9cf2b17 100644 --- a/src/Storages/StoragePostgreSQL.h +++ b/src/Storages/StoragePostgreSQL.h @@ -11,6 +11,7 @@ #include #include "pqxx/pqxx" + namespace DB { diff --git a/src/TableFunctions/TableFunctionPostgreSQL.cpp b/src/TableFunctions/TableFunctionPostgreSQL.cpp index 4f8ffecc89a..bbbc9742015 100644 --- a/src/TableFunctions/TableFunctionPostgreSQL.cpp +++ b/src/TableFunctions/TableFunctionPostgreSQL.cpp @@ -11,6 +11,7 @@ #include "registerTableFunctions.h" #include + namespace DB { diff --git a/src/TableFunctions/TableFunctionPostgreSQL.h b/src/TableFunctions/TableFunctionPostgreSQL.h index 9bdb4e2e32f..7af01ecb053 100644 --- a/src/TableFunctions/TableFunctionPostgreSQL.h +++ b/src/TableFunctions/TableFunctionPostgreSQL.h @@ -8,6 +8,7 @@ #include #include "pqxx/pqxx" + namespace DB {