When working with timestamped data, it may be necessary to convert timestamp values to or from UTC, or to offset timestamp values by a fixed duration. The following sections describe how QuestDB handles timestamps natively, how to use built-in functions for working with time zone conversions, and general hints for working with time zones in QuestDB.
The native timestamp format used by QuestDB is a Unix timestamp in microsecond resolution. Although timestamps in nanoseconds will be parsed, the output will be truncated to microseconds. QuestDB does not store time zone information alongside timestamp values and therefore it should be assumed that all timestamps are in UTC.
The following example shows how a Unix timestamp in microseconds may be passed into a timestamp column directly:
Timestamps may also be inserted as strings in the following way:
When inserting timestamps into a table, it is also possible to use timestamp units to define the timestamp format, in order to process trailing zeros in exported data sources such as PostgreSQL:
The output maintains microsecond resolution:
In order to simplify working with time zones, QuestDB uses the tz time zone database which is standard in the Java ecosystem. This time zone database is used internally in time zone lookup and in operations relating to timestamp value conversion to and from time zones.
For this reason, a time zone may be referenced by abbreviated name, by full time zone name or by UTC offset:
|Abbreviation||Time zone name||UTC offset|
It's strongly advised not to use the three-letter ID or abbreviation for time zones for the following reason:
The same abbreviation is often used for multiple time zones (for example, "CST" could be U.S. "Central Standard Time" and "China Standard Time"), and the Java platform can then only recognize one of them
Therefore, choosing a geographic region which observes a time zone
"Europe/Prague") or a UTC offset value (
more reliable when referring to time zones. Instructions for converting to and
from time zones are described in the
Converting timestamps to and from time zones
The current QuestDB time zone database uses the English locale but support
for additional locales may be added in future. Referring to time zones which are
outdated or not recognized results in a
invalid timezone name error. The
following resources may be used for hints how to refer to time zones by ID or
- The official list maintained by IANA
- Java's getAvailableZoneIds method
- Wiki entry on tz database time zones (this is a convenient reference, but may not be 100% accurate)
Users should be aware that the time zone database contains both current and historic transitions for various time zones. Therefore time zone conversions must take the historic time zone transitions into account based on the timestamp values.
The upstream project updates past time zones as new information becomes available. These changes are typically related to daylight saving time (DST) start and end date transitions and, on rare occasions, time zone name changes.
The tz database version used by QuestDB is determined by the JDK version used at build time and therefore updates to the time zone database are directly influenced by this JDK version. To find the JDK version used by a QuestDB build, run the following SQL:
|Build Information: QuestDB 6.0.3, JDK 11.0.7, Commit Hash a6afbadb9b9419d47cca1bf86fa13fdadf08bda4|
For convenience, QuestDB includes two functions for time zone conversions on timestamp values.
These functions are used to convert a Unix timestamp, or a string equivalent cast to timestamp as follows:
The to_timezone() and
to_utc() functions may use UTC
offset for converting timestamp values. In some cases, this can be more reliable
than string or time zone ID conversion given historic changes to time zone names
or transitions. The following example takes a Unix timestamp in microseconds and
converts it to a time zone
+2 hours offset from UTC: