#pragma once #include "config.h" #if USE_LIBPQXX #include #include namespace DB { struct PostgreSQLTableStructure { struct PGAttribute { Int32 atttypid; Int32 atttypmod; Int32 attnum; bool atthasdef; char attgenerated; std::string attr_def; }; using Attributes = std::unordered_map; struct ColumnsInfo { NamesAndTypesList columns; Attributes attributes; std::vector names; ColumnsInfo(NamesAndTypesList && columns_, Attributes && attributes_) : columns(columns_), attributes(attributes_) {} }; using ColumnsInfoPtr = std::shared_ptr; ColumnsInfoPtr physical_columns; ColumnsInfoPtr primary_key_columns; ColumnsInfoPtr replica_identity_columns; }; using PostgreSQLTableStructurePtr = std::unique_ptr; /// We need order for materialized version. std::set fetchPostgreSQLTablesList(pqxx::connection & connection, const String & postgres_schema); PostgreSQLTableStructure fetchPostgreSQLTableStructure( pqxx::connection & connection, const String & postgres_table, const String & postgres_schema, bool use_nulls = true); template PostgreSQLTableStructure fetchPostgreSQLTableStructure( T & tx, const String & postgres_table, const String & postgres_schema, bool use_nulls = true, bool with_primary_key = false, bool with_replica_identity_index = false, const Strings & columns = {}); template std::set fetchPostgreSQLTablesList(T & tx, const String & postgres_schema); } #endif