mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 19:13:16 +08:00
Currently, the internal metadata tables for hypertables track time as a BIGINT integer. Converting hypertable time columns in TIMESTAMP format to this internal representation requires using Postgres' conversion functions that are imprecise due to floating-point arithmetic. This patch adds C-based conversion functions that offer the following conversions using accurate integer arithmetic: - TIMESTAMP to UNIX epoch BIGINT in microseconds - UNIX epoch BIGINT in microseconds to TIMESTAMP - TIMESTAMP to Postgres epoch BIGINT in microseconds - Postgres epoch BIGINT in microseconds to TIMESTAMP The downside of the UNIX epoch functions are that they don't offer the full date range as offered by the Postgres to_timestamp() function. This is because of the required epoch shift might otherwise overflow the BIGINT. All functions should, however, offer appropriate range checks and will throw errors if outside the range.