diff --git a/c/driver/postgresql/postgres_type.h b/c/driver/postgresql/postgres_type.h index e8de6e1ba4..43608f2c83 100644 --- a/c/driver/postgresql/postgres_type.h +++ b/c/driver/postgresql/postgres_type.h @@ -216,9 +216,12 @@ class PostgresType { break; // ---- Numeric/Decimal------------------- - case PostgresTypeId::kNumeric: + case PostgresTypeId::kNumeric: { NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema, NANOARROW_TYPE_STRING)); + NANOARROW_RETURN_NOT_OK(AddPostgresTypeMetadata(schema)); + break; + } // ---- Binary/string -------------------- case PostgresTypeId::kChar: @@ -284,13 +287,7 @@ class PostgresType { // can still return the bytes postgres gives us and attach the type name as // metadata NANOARROW_RETURN_NOT_OK(ArrowSchemaSetType(schema, NANOARROW_TYPE_BINARY)); - nanoarrow::UniqueBuffer buffer; - ArrowMetadataBuilderInit(buffer.get(), nullptr); - NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderAppend( - buffer.get(), ArrowCharView("ADBC:postgresql:typname"), - ArrowCharView(typname_.c_str()))); - NANOARROW_RETURN_NOT_OK( - ArrowSchemaSetMetadata(schema, reinterpret_cast(buffer->data))); + NANOARROW_RETURN_NOT_OK(AddPostgresTypeMetadata(schema)); break; } } @@ -309,6 +306,19 @@ class PostgresType { std::string typname_; std::string field_name_; std::vector children_; + + static constexpr const char* kPostgresTypeKey = "ADBC:postgresql:typname"; + + ArrowErrorCode AddPostgresTypeMetadata(ArrowSchema* schema) const { + nanoarrow::UniqueBuffer buffer; + ArrowMetadataBuilderInit(buffer.get(), nullptr); + NANOARROW_RETURN_NOT_OK(ArrowMetadataBuilderAppend( + buffer.get(), ArrowCharView(kPostgresTypeKey), ArrowCharView(typname_.c_str()))); + NANOARROW_RETURN_NOT_OK( + ArrowSchemaSetMetadata(schema, reinterpret_cast(buffer->data))); + + return NANOARROW_OK; + } }; // Because type information is stored in a database's pg_type table, it can't