TIMESTAMPTZ.
Alias: FROM_UNIXTIME - only accepts one parameter of type DOUBLE PRECISION
Conversion function
Converts the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) to a TIMESTAMPTZ value.
Syntax
TO_TIMESTAMP(<seconds>)
Parameters
Return Type
TIMESTAMPTZ
Remarks
TO_TIMESTAMP(<seconds>) is the inverse function of EXTRACT(EPOCH FROM TIMESTAMPTZ).
Example
Formatting function
Converts a string toTIMESTAMPTZ type (i.e., timestamp with time zone) using format.
Syntax
Parameters
Accepted
<format> patterns include the following specifications:
Usage notes for formatting
- Case letters in the input
<expression>are ignored - A separator (non-digit and non-letter) in the
<format>string will match exactly one separator or is skipped - Any non-separator in the
<format>that is not part of a format option will match exactly one other character. - Any character in quotes
"will match exactly one other character. - If the year format specification is
'YYY','YY', or'Y'and the supplied year is less than four digits, the year will be adjusted to be nearest to the year 2020, (e.g.,80becomes1980). - Milliseconds and microseconds are interpreted as subseconds in the form
ss.xxx[xxx]. This means thatTO_TIMESTAMP('30.7', 'SS.MS')is not 7 milliseconds, but 700, because it will be treated as 30 + 0.7 seconds. To achieve 7 milliseconds, one ust write30.007instead. - Modifiers (e.g.,
'FM') are not supported.
FF1, FF2, FF3, FF4, FF5, FF6, SSSS, SSSSS, IYYY, IYY, IY, I, BC, AD, B_DOT_C_DOT, A_DOT_D_DOT, DAY, DY, DDD, IDDD, D, ID, W, WW, IW, CC, J, Q.
Using them in the format string raises an error.
Examples
The example below shows our separators and non-separators can cause skips. The separator' ' (space) in the <format> matches the other separator '/' in the <expression>.
The non-separator 'x' will match any other character, in this case the 'a'. Lastly, the two separators '++' will match up to two other separators,
here the first 'x' matches '.' while the second 'x' will simply be ignored as no other separators follow.
Rows: 1Execution time: 5.02ms
YYY was used to match a less than four digit number. To receive the exact year '180' use YYYY instead.
Furthermore, as the three separators are quotes "..." they will match any character (separator or non-separator) which in this case is 'ar '.
Rows: 1Execution time: 5.44ms
Rows: 1Execution time: 5.66ms
Rows: 1Execution time: 5.02ms
Rows: 1Execution time: 6.32ms
Rows: 1Execution time: 6.13ms