Skip to content

Commit

Permalink
timestamp_ms, timestamp_s converted accordingly when received from du…
Browse files Browse the repository at this point in the history
…ckdb
  • Loading branch information
destrex271 committed Jan 16, 2025
1 parent bc88d9c commit 62c517f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/pgduckdb_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,24 @@ ConvertDateDatum(const duckdb::Value &value) {

inline Datum
ConvertTimestampDatum(const duckdb::Value &value) {
duckdb::timestamp_t timestamp = value.GetValue<duckdb::timestamp_t>();
return timestamp.value - pgduckdb::PGDUCKDB_DUCK_TIMESTAMP_OFFSET;
// Extract raw int64_t value of timestamp
int64_t rawValue = value.GetValue<int64_t>();

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
Expand Down

0 comments on commit 62c517f

Please sign in to comment.