Check table in a suggested way

This commit is contained in:
kssenii 2021-04-08 14:02:15 +00:00
parent b544c9fe9a
commit 4482a35a3a
2 changed files with 5 additions and 13 deletions

View File

@ -67,14 +67,14 @@ class PostgreSQLTransactionBlockInputStream : public PostgreSQLBlockInputStream<
{ {
public: public:
using Base = PostgreSQLBlockInputStream<pqxx::ReplicationTransaction>; using Base = PostgreSQLBlockInputStream<T>;
PostgreSQLTransactionBlockInputStream( PostgreSQLTransactionBlockInputStream(
std::shared_ptr<T> tx_, std::shared_ptr<T> tx_,
const std::string & query_str_, const std::string & query_str_,
const Block & sample_block_, const Block & sample_block_,
const UInt64 max_block_size_) const UInt64 max_block_size_)
: PostgreSQLBlockInputStream<pqxx::ReplicationTransaction>(tx_, query_str_, sample_block_, max_block_size_, false) {} : PostgreSQLBlockInputStream<T>(tx_, query_str_, sample_block_, max_block_size_, false) {}
void readPrefix() override void readPrefix() override
{ {

View File

@ -12,6 +12,7 @@
#include <DataTypes/DataTypeDateTime.h> #include <DataTypes/DataTypeDateTime.h>
#include <boost/algorithm/string/split.hpp> #include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp> #include <boost/algorithm/string/trim.hpp>
#include <Common/quoteString.h>
#include <pqxx/pqxx> #include <pqxx/pqxx>
@ -161,21 +162,12 @@ PostgreSQLTableStructure fetchPostgreSQLTableStructure(
{ {
PostgreSQLTableStructure table; PostgreSQLTableStructure table;
if (postgres_table_name.find('\'') != std::string::npos
|| postgres_table_name.find('\\') != std::string::npos)
{
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"PostgreSQL table name cannot contain single quote or backslash characters, passed {}",
postgres_table_name);
}
std::string query = fmt::format( std::string query = fmt::format(
"SELECT attname AS name, format_type(atttypid, atttypmod) AS type, " "SELECT attname AS name, format_type(atttypid, atttypmod) AS type, "
"attnotnull AS not_null, attndims AS dims " "attnotnull AS not_null, attndims AS dims "
"FROM pg_attribute " "FROM pg_attribute "
"WHERE attrelid = '{}'::regclass " "WHERE attrelid = {}::regclass "
"AND NOT attisdropped AND attnum > 0", postgres_table_name); "AND NOT attisdropped AND attnum > 0", quoteString(postgres_table_name));
table.columns = readNamesAndTypesList(tx, postgres_table_name, query, use_nulls, false); table.columns = readNamesAndTypesList(tx, postgres_table_name, query, use_nulls, false);