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 <common/logger_useful.h>
namespace DB
{
@ -26,7 +27,6 @@ namespace ErrorCodes
extern const int BAD_ARGUMENTS;
}
PostgreSQLBlockInputStream::PostgreSQLBlockInputStream(
ConnectionPtr connection_,
const std::string & query_str_,

View File

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

View File

@ -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 &)
{

View File

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

View File

@ -14,6 +14,7 @@
#include <boost/algorithm/string/trim.hpp>
#include <pqxx/pqxx>
namespace DB
{
@ -57,6 +58,11 @@ std::shared_ptr<NamesAndTypesList> 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;

View File

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

View File

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

View File

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

View File

@ -157,9 +157,11 @@ public:
void writeSuffix() override
{
if (stream_inserter)
{
stream_inserter->complete();
work->commit();
}
}
/// Cannot just use serializeAsText for array data type even though it converts perfectly

View File

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

View File

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

View File

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