From 62c517f6cf624618d42132ebb85ec82c965c96c8 Mon Sep 17 00:00:00 2001 From: Akshat Jaimini Date: Thu, 16 Jan 2025 21:05:50 +0530 Subject: [PATCH] timestamp_ms, timestamp_s converted accordingly when received from duckdb --- src/pgduckdb_types.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/pgduckdb_types.cpp b/src/pgduckdb_types.cpp index 69431921..77ad1265 100644 --- a/src/pgduckdb_types.cpp +++ b/src/pgduckdb_types.cpp @@ -221,8 +221,24 @@ ConvertDateDatum(const duckdb::Value &value) { inline Datum ConvertTimestampDatum(const duckdb::Value &value) { - duckdb::timestamp_t timestamp = value.GetValue(); - return timestamp.value - pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET; + // Extract raw int64_t value of timestamp + int64_t rawValue = value.GetValue(); + + switch(value.type().id()){ + case duckdb::LogicalType::TIMESTAMP_MS: + // 1 ms = 10^3 micro-sec + rawValue *= 1000; + break; + case duckdb::LogicalType::TIMESTAMP_NS: + // 1 ns = 10^-3 micro-sec + rawValue /= 1000; + break; + case duckdb::LogicalType::TIMESTAMP_S: + // 1 s = 10^6 micro-sec + rawValue *= 1000000; + break; + } + return rawValue - pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET; } inline Datum