TIMESTAMP data type.
Overview
The
TIMESTAMP data type represents a date and time with microsecond resolution independent of a time zone.
To represent an absolute point in time, use TIMESTAMPTZ.
The range ends at 9999-12-30 22:00:00.999999 rather than at the end of the year 9999: it is the largest value that stays in the year 9999 after shifting it by any UTC offset (up to 25:59:59), so every TIMESTAMPTZ value can be displayed in every time zone. Converting a TIMESTAMP close to the maximum to TIMESTAMPTZ (or back) can still leave the range when the conversion shifts it past the maximum.
A literal past the maximum, for example TIMESTAMP '9999-12-31', is rejected as out of range.
Literal string interpretation
TIMESTAMP literals follow the ISO 8601 and RFC 3339 format: YYYY-[M]M-[D]D[( |T)[h]h:[m]m:[s]s[.f]].
YYYY: Four-digit year (0001-9999)[M]M: One or two digit month (01-12)[D]D: One or two digit day (01-31)( |T): A space orTseparator[h]h: One or two digit hour (00-23)[m]m: One or two digit minute (00-59)[s]s: One or two digit second (00-59)[.f]: Up to six digits after the decimal separator (000000-999999)
00:00:00.000000.
Examples
Functions and operators
Type conversions
TheTIMESTAMP data type can be cast to and from types as follows:
To TIMESTAMP
From TIMESTAMP
Comparison operators
A
TIMESTAMP value is also comparable with a DATE or TIMESTAMPTZ value:
- The
DATEvalue is cast to theTIMESTAMPtype for comparison with aTIMESTAMPvalue. - The
TIMESTAMPvalue is cast to theTIMESTAMPTZtype for comparison with aTIMESTAMPTZvalue.
Arithmetic operators
Arithmetic with intervals can be used to add or subtract a duration to or from a timestamp. The result is of typeTIMESTAMP.
Rows: 1Execution time: 9.05ms
Rows: 1Execution time: 6.40ms
Serialization and deserialization
Text, CSV, JSON
In the text, CSV, and JSON format, aTIMESTAMP value is output as a YYYY-MM-DD hh:mm:ss[.f] string.
Firebolt outputs as few digits after the decimal separator as possible (at most six).
Input is accepted in the literal format described above: YYYY-[M]M-[D]D[( |T)[h]h:[m]m:[s]s[.f]].
Parquet
TIMESTAMP maps to Parquet’s 64-bit signed integer TIMESTAMP type with the parameter isAdjustedToUTC set to false and unit set to MICROS, also representing the number of microseconds before or after 1970-01-01 00:00:00.000000.
Avro
It’s not possible to import directly from Avro into aTIMESTAMP column.
Instead, first import using a TIMESTAMPTZ column and then use the AT TIME ZONE expression to convert to TIMESTAMP.
ORC
TIMESTAMP maps to ORC’s “timezone-unaware” logical type “timestamp”.