clickhouse 连接 opengauss 报错

使用clickhouse通过postgresql表函数直接抽取 opengauss 数据时报错
SELECT id FROM postgresql(‘192.168.31.247:5435’, ‘postgres’, ‘newtable’, ‘dbuser’, ‘xxxx’, ‘test1’)
该问题在 clickhouse 24.8 及以后版本中出现,貌似是因为获取不到表结构的元数据信息导致。

clickhouse 错误日志如下

2025.12.12 11:54:31.499425 [ 31280 ] {efd3432c-b54c-4ce7-997a-f69afc4111e6} executeQuery: std::exception. Code: 1001, type: pqxx::conversion_error, e.what() = Attempt to convert null to NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE. (version 24.8.14.39 (official build)) (from 192.168.31.210:49814) (in query: SELECT id FROM postgresql(‘192.168.31.247:5435’, ‘postgres’, ‘newtable’, ‘dbuser’, ‘[HIDDEN]’, ‘test1’) LIMIT 0, 200), Stack trace (when copying this message, always include the lines below):

  1. pqxx::internal::throw_null_conversion(String const&) @ 0x000000001708d25e
  2. pqxx::stream_from& pqxx::stream_from::operator>><std::tuple<String, String, String, unsigned short, String, String, String, String>>(std::tuple<String, String, String, unsigned short, String, String, String, String>&) @ 0x000000001086ccf5
  3. std::shared_ptrDB::PostgreSQLTableStructure::ColumnsInfo DB::readNamesAndTypesList<pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>>(pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>&, String const&, String const&, bool, bool) @ 0x000000001085c783
  4. DB::PostgreSQLTableStructure DB::fetchPostgreSQLTableStructure<pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>>(pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>&, String const&, String const&, bool, bool, bool) @ 0x000000001085a8a5
  5. DB::fetchPostgreSQLTableStructure(pqxx::connection&, String const&, String const&, bool) @ 0x000000001086b6d6
  6. DB::StoragePostgreSQL::getTableStructureFromData(std::shared_ptrpostgres::PoolWithFailover const&, String const&, String const&, std::shared_ptr<DB::Context const> const&) @ 0x0000000011a22176
  7. DB::StoragePostgreSQL::StoragePostgreSQL(DB::StorageID const&, std::shared_ptrpostgres::PoolWithFailover, String const&, DB::ColumnsDescription const&, DB::ConstraintsDescription const&, String const&, std::shared_ptr<DB::Context const>, String const&, String const&) @ 0x0000000011a21caa
  8. DB::(anonymous namespace)::TableFunctionPostgreSQL::executeImpl(std::shared_ptrDB::IAST const&, std::shared_ptr<DB::Context const>, String const&, DB::ColumnsDescription, bool) const (.3bc787d845b295ae09d205ff72104d63) @ 0x000000000fb40ab8
  9. DB::ITableFunction::execute(std::shared_ptrDB::IAST const&, std::shared_ptr<DB::Context const>, String const&, DB::ColumnsDescription, bool, bool) const @ 0x000000000fdefbb6
  10. DB::Context::executeTableFunction(std::shared_ptrDB::IAST const&, std::shared_ptrDB::ITableFunction const&) @ 0x0000000010b62c5f
  11. DB::QueryAnalyzer::resolveTableFunction(std::shared_ptrDB::IQueryTreeNode&, DB::IdentifierResolveScope&, DB::QueryExpressionsAliasVisitor&, bool) @ 0x0000000010aaa3e9
  12. DB::QueryAnalyzer::resolveQueryJoinTreeNode(std::shared_ptrDB::IQueryTreeNode&, DB::IdentifierResolveScope&, DB::QueryExpressionsAliasVisitor&) @ 0x0000000010ad629c
  13. DB::QueryAnalyzer::resolveQuery(std::shared_ptrDB::IQueryTreeNode const&, DB::IdentifierResolveScope&) @ 0x0000000010a9a05f
  14. DB::QueryAnalyzer::resolve(std::shared_ptrDB::IQueryTreeNode&, std::shared_ptrDB::IQueryTreeNode const&, std::shared_ptr<DB::Context const>) @ 0x0000000010a9840c
  15. DB::QueryAnalysisPass::run(std::shared_ptrDB::IQueryTreeNode&, std::shared_ptr<DB::Context const>) @ 0x0000000010a97ce0
  16. DB::QueryTreePassManager::run(std::shared_ptrDB::IQueryTreeNode) @ 0x0000000010fa2eb6
  17. DB::(anonymous namespace)::buildQueryTreeAndRunPasses(std::shared_ptrDB::IAST const&, DB::SelectQueryOptions const&, std::shared_ptr<DB::Context const> const&, std::shared_ptrDB::IStorage const&) (.llvm.5846909550072536389) @ 0x000000001107091d
  18. DB::InterpreterSelectQueryAnalyzer::InterpreterSelectQueryAnalyzer(std::shared_ptrDB::IAST const&, std::shared_ptr<DB::Context const> const&, DB::SelectQueryOptions const&, std::vector<String, std::allocator> const&) @ 0x000000001106e8fc
  19. std::unique_ptr<DB::IInterpreter, std::default_deleteDB::IInterpreter> std::__function::__policy_invoker<std::unique_ptr<DB::IInterpreter, std::default_deleteDB::IInterpreter> (DB::InterpreterFactory::Arguments const&)>::__call_impl<std::__function::__default_alloc_func<DB::registerInterpreterSelectQueryAnalyzer(DB::InterpreterFactory&)::$_0, std::unique_ptr<DB::IInterpreter, std::default_deleteDB::IInterpreter> (DB::InterpreterFactory::Arguments const&)>>(std::__function::__policy_storage const*, DB::InterpreterFactory::Arguments const&) (.llvm.5846909550072536389) @ 0x00000000110725e2
  20. DB::InterpreterFactory::get(std::shared_ptrDB::IAST&, std::shared_ptrDB::Context, DB::SelectQueryOptions const&) @ 0x000000001100442c
  21. DB::executeQueryImpl(char const*, char const*, std::shared_ptrDB::Context, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x00000000113bd361
  22. DB::executeQuery(DB::ReadBuffer&, DB::WriteBuffer&, bool, std::shared_ptrDB::Context, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optionalDB::FormatSettings const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optionalDB::FormatSettings const&)>) @ 0x00000000113c2ce4
  23. DB::HTTPHandler::processQuery(DB::HTTPServerRequest&, DB::HTMLForm&, DB::HTTPServerResponse&, DB::HTTPHandler::Output&, std::optionalDB::CurrentThread::QueryScope&, StrongTypedef<unsigned long, ProfileEvents::EventTag> const&) @ 0x00000000124c3956
  24. DB::HTTPHandler::handleRequest(DB::HTTPServerRequest&, DB::HTTPServerResponse&, StrongTypedef<unsigned long, ProfileEvents::EventTag> const&) @ 0x00000000124c78b9
  25. DB::HTTPServerConnection::run() @ 0x000000001256682a
  26. Poco::Net::TCPServerConnection::start() @ 0x000000001533c547
  27. Poco::Net::TCPServerDispatcher::run() @ 0x000000001533c9d9
  28. Poco::PooledThread::run() @ 0x0000000015309981
  29. Poco::ThreadImpl::runnableEntry(void*) @ 0x0000000015307f3d
  30. start_thread @ 0x0000000000007ea5
  31. __clone @ 0x00000000000feb0d

2025.12.12 11:54:31.499578 [ 31280 ] {efd3432c-b54c-4ce7-997a-f69afc4111e6} DynamicQueryHandler: std::exception. Code: 1001, type: pqxx::conversion_error, e.what() = Attempt to convert null to NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE., Stack trace (when copying this message, always include the lines below):

  1. pqxx::internal::throw_null_conversion(String const&) @ 0x000000001708d25e
  2. pqxx::stream_from& pqxx::stream_from::operator>><std::tuple<String, String, String, unsigned short, String, String, String, String>>(std::tuple<String, String, String, unsigned short, String, String, String, String>&) @ 0x000000001086ccf5
  3. std::shared_ptrDB::PostgreSQLTableStructure::ColumnsInfo DB::readNamesAndTypesList<pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>>(pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>&, String const&, String const&, bool, bool) @ 0x000000001085c783
  4. DB::PostgreSQLTableStructure DB::fetchPostgreSQLTableStructure<pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>>(pqxx::transaction<(pqxx::isolation_level)0, (pqxx::write_policy)0>&, String const&, String const&, bool, bool, bool) @ 0x000000001085a8a5
  5. DB::fetchPostgreSQLTableStructure(pqxx::connection&, String const&, String const&, bool) @ 0x000000001086b6d6
  6. DB::StoragePostgreSQL::getTableStructureFromData(std::shared_ptrpostgres::PoolWithFailover const&, String const&, String const&, std::shared_ptr<DB::Context const> const&) @ 0x0000000011a22176
  7. DB::StoragePostgreSQL::StoragePostgreSQL(DB::StorageID const&, std::shared_ptrpostgres::PoolWithFailover, String const&, DB::ColumnsDescription const&, DB::ConstraintsDescription const&, String const&, std::shared_ptr<DB::Context const>, String const&, String const&) @ 0x0000000011a21caa
  8. DB::(anonymous namespace)::TableFunctionPostgreSQL::executeImpl(std::shared_ptrDB::IAST const&, std::shared_ptr<DB::Context const>, String const&, DB::ColumnsDescription, bool) const (.3bc787d845b295ae09d205ff72104d63) @ 0x000000000fb40ab8
  9. DB::ITableFunction::execute(std::shared_ptrDB::IAST const&, std::shared_ptr<DB::Context const>, String const&, DB::ColumnsDescription, bool, bool) const @ 0x000000000fdefbb6
  10. DB::Context::executeTableFunction(std::shared_ptrDB::IAST const&, std::shared_ptrDB::ITableFunction const&) @ 0x0000000010b62c5f
  11. DB::QueryAnalyzer::resolveTableFunction(std::shared_ptrDB::IQueryTreeNode&, DB::IdentifierResolveScope&, DB::QueryExpressionsAliasVisitor&, bool) @ 0x0000000010aaa3e9
  12. DB::QueryAnalyzer::resolveQueryJoinTreeNode(std::shared_ptrDB::IQueryTreeNode&, DB::IdentifierResolveScope&, DB::QueryExpressionsAliasVisitor&) @ 0x0000000010ad629c
  13. DB::QueryAnalyzer::resolveQuery(std::shared_ptrDB::IQueryTreeNode const&, DB::IdentifierResolveScope&) @ 0x0000000010a9a05f
  14. DB::QueryAnalyzer::resolve(std::shared_ptrDB::IQueryTreeNode&, std::shared_ptrDB::IQueryTreeNode const&, std::shared_ptr<DB::Context const>) @ 0x0000000010a9840c
  15. DB::QueryAnalysisPass::run(std::shared_ptrDB::IQueryTreeNode&, std::shared_ptr<DB::Context const>) @ 0x0000000010a97ce0
  16. DB::QueryTreePassManager::run(std::shared_ptrDB::IQueryTreeNode) @ 0x0000000010fa2eb6
  17. DB::(anonymous namespace)::buildQueryTreeAndRunPasses(std::shared_ptrDB::IAST const&, DB::SelectQueryOptions const&, std::shared_ptr<DB::Context const> const&, std::shared_ptrDB::IStorage const&) (.llvm.5846909550072536389) @ 0x000000001107091d
  18. DB::InterpreterSelectQueryAnalyzer::InterpreterSelectQueryAnalyzer(std::shared_ptrDB::IAST const&, std::shared_ptr<DB::Context const> const&, DB::SelectQueryOptions const&, std::vector<String, std::allocator> const&) @ 0x000000001106e8fc
  19. std::unique_ptr<DB::IInterpreter, std::default_deleteDB::IInterpreter> std::__function::__policy_invoker<std::unique_ptr<DB::IInterpreter, std::default_deleteDB::IInterpreter> (DB::InterpreterFactory::Arguments const&)>::__call_impl<std::__function::__default_alloc_func<DB::registerInterpreterSelectQueryAnalyzer(DB::InterpreterFactory&)::$_0, std::unique_ptr<DB::IInterpreter, std::default_deleteDB::IInterpreter> (DB::InterpreterFactory::Arguments const&)>>(std::__function::__policy_storage const*, DB::InterpreterFactory::Arguments const&) (.llvm.5846909550072536389) @ 0x00000000110725e2
  20. DB::InterpreterFactory::get(std::shared_ptrDB::IAST&, std::shared_ptrDB::Context, DB::SelectQueryOptions const&) @ 0x000000001100442c
  21. DB::executeQueryImpl(char const*, char const*, std::shared_ptrDB::Context, DB::QueryFlags, DB::QueryProcessingStage::Enum, DB::ReadBuffer*) @ 0x00000000113bd361
  22. DB::executeQuery(DB::ReadBuffer&, DB::WriteBuffer&, bool, std::shared_ptrDB::Context, std::function<void (DB::QueryResultDetails const&)>, DB::QueryFlags, std::optionalDB::FormatSettings const&, std::function<void (DB::IOutputFormat&, String const&, std::shared_ptr<DB::Context const> const&, std::optionalDB::FormatSettings const&)>) @ 0x00000000113c2ce4
  23. DB::HTTPHandler::processQuery(DB::HTTPServerRequest&, DB::HTMLForm&, DB::HTTPServerResponse&, DB::HTTPHandler::Output&, std::optionalDB::CurrentThread::QueryScope&, StrongTypedef<unsigned long, ProfileEvents::EventTag> const&) @ 0x00000000124c3956
  24. DB::HTTPHandler::handleRequest(DB::HTTPServerRequest&, DB::HTTPServerResponse&, StrongTypedef<unsigned long, ProfileEvents::EventTag> const&) @ 0x00000000124c78b9
  25. DB::HTTPServerConnection::run() @ 0x000000001256682a
  26. Poco::Net::TCPServerConnection::start() @ 0x000000001533c547
  27. Poco::Net::TCPServerDispatcher::run() @ 0x000000001533c9d9
  28. Poco::PooledThread::run() @ 0x0000000015309981
  29. Poco::ThreadImpl::runnableEntry(void*) @ 0x0000000015307f3d
  30. start_thread @ 0x0000000000007ea5
  31. __clone @ 0x00000000000feb0d
    (version 24.8.14.39 (official build))