From e3a22bb60daeeefe2cd56faf3c561d6535a3fe9f Mon Sep 17 00:00:00 2001 From: dentiny Date: Wed, 26 Feb 2025 13:12:40 +0000 Subject: [PATCH] add function guard --- src/pgduckdb_types.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pgduckdb_types.cpp b/src/pgduckdb_types.cpp index 0576087..8a1f048 100644 --- a/src/pgduckdb_types.cpp +++ b/src/pgduckdb_types.cpp @@ -340,9 +340,12 @@ ConvertNumericDatum(const duckdb::Value &value) { // Special handle duckdb VARINT type. if (value.type().id() == duckdb::LogicalTypeId::VARINT) { - std::string value_str = value.ToString(); - Datum pg_numeric = DirectFunctionCall3(numeric_in, CStringGetDatum(value_str.c_str()), - ObjectIdGetDatum(InvalidOid), Int32GetDatum(-1)); + // The performant way to handle the translation is to parse VARINT out, here we leverage string conversion and + // parsing mainly for code simplicity. + const std::string value_str = value.ToString(); + const Datum pg_numeric = PostgresFunctionGuard( + DirectFunctionCall3(numeric_in, /*str=*/CStringGetDatum(value_str.c_str()), + /*typelem=*/ObjectIdGetDatum(InvalidOid), /*typmod=*/Int32GetDatum(-1))); return pg_numeric; }