This commit is contained in:
kssenii 2021-01-11 10:23:44 +00:00
parent 6ec59f1304
commit 38a9cba850
12 changed files with 24 additions and 3 deletions

View File

@ -18,6 +18,7 @@
#include <ext/range.h> #include <ext/range.h>
#include <common/logger_useful.h> #include <common/logger_useful.h>
namespace DB namespace DB
{ {
@ -26,7 +27,6 @@ namespace ErrorCodes
extern const int BAD_ARGUMENTS; extern const int BAD_ARGUMENTS;
} }
PostgreSQLBlockInputStream::PostgreSQLBlockInputStream( PostgreSQLBlockInputStream::PostgreSQLBlockInputStream(
ConnectionPtr connection_, ConnectionPtr connection_,
const std::string & query_str_, const std::string & query_str_,

View File

@ -11,6 +11,7 @@
#include <Core/Field.h> #include <Core/Field.h>
#include <pqxx/pqxx> #include <pqxx/pqxx>
namespace DB namespace DB
{ {
using ConnectionPtr = std::shared_ptr<pqxx::connection>; using ConnectionPtr = std::shared_ptr<pqxx::connection>;

View File

@ -101,7 +101,12 @@ bool DatabasePostgreSQL::checkPostgresTable(const String & table_name) const
try 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 &) catch (pqxx::undefined_table const &)
{ {

View File

@ -11,6 +11,7 @@
#include <Parsers/ASTCreateQuery.h> #include <Parsers/ASTCreateQuery.h>
#include <Storages/StoragePostgreSQL.h> #include <Storages/StoragePostgreSQL.h>
namespace DB namespace DB
{ {

View File

@ -14,6 +14,7 @@
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <pqxx/pqxx> #include <pqxx/pqxx>
namespace DB namespace DB
{ {
@ -57,6 +58,11 @@ std::shared_ptr<NamesAndTypesList> fetchPostgreSQLTableStructure(ConnectionPtr c
"PostgreSQL table {}.{} does not exist", "PostgreSQL table {}.{} does not exist",
connection->dbname(), postgres_table_name), ErrorCodes::UNKNOWN_TABLE); connection->dbname(), postgres_table_name), ErrorCodes::UNKNOWN_TABLE);
} }
catch (Exception & e)
{
e.addMessage("while fetching postgresql table structure");
throw;
}
if (columns.empty()) if (columns.empty())
return nullptr; return nullptr;

View File

@ -7,6 +7,7 @@
#if USE_LIBPQXX #if USE_LIBPQXX
#include <Storages/StoragePostgreSQL.h> #include <Storages/StoragePostgreSQL.h>
namespace DB namespace DB
{ {

View File

@ -11,6 +11,7 @@
#include "readInvalidateQuery.h" #include "readInvalidateQuery.h"
#endif #endif
namespace DB namespace DB
{ {

View File

@ -14,6 +14,7 @@
#include <Storages/StoragePostgreSQL.h> #include <Storages/StoragePostgreSQL.h>
#include <pqxx/pqxx> #include <pqxx/pqxx>
namespace DB namespace DB
{ {

View File

@ -157,8 +157,10 @@ public:
void writeSuffix() override void writeSuffix() override
{ {
if (stream_inserter) if (stream_inserter)
{
stream_inserter->complete(); stream_inserter->complete();
work->commit(); work->commit();
}
} }

View File

@ -11,6 +11,7 @@
#include <DataStreams/IBlockOutputStream.h> #include <DataStreams/IBlockOutputStream.h>
#include "pqxx/pqxx" #include "pqxx/pqxx"
namespace DB namespace DB
{ {

View File

@ -11,6 +11,7 @@
#include "registerTableFunctions.h" #include "registerTableFunctions.h"
#include <Databases/PostgreSQL/FetchFromPostgreSQL.h> #include <Databases/PostgreSQL/FetchFromPostgreSQL.h>
namespace DB namespace DB
{ {

View File

@ -8,6 +8,7 @@
#include <Storages/StoragePostgreSQL.h> #include <Storages/StoragePostgreSQL.h>
#include "pqxx/pqxx" #include "pqxx/pqxx"
namespace DB namespace DB
{ {