Re: BUG #16797: EXTRACT(EPOCH FROM timestamp) is not using local timezone
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Dana Burd <djburd@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2021-01-01T17:18:12Z
Lists: pgsql-bugs
Dana Burd <djburd@gmail.com> writes:
> Can I suggest a slight alteration in the (9.9.1. EXTRACT) epoch
> documentation to help others:
> "For timestamp with time zone values, the number of seconds since
> 1970-01-01 00:00:00 UTC (can be negative); for date and timestamp values,
> the number of seconds since 1970-01-01 00:00:00 UTC (date and timestamp
> will assume UTC regardless of local timezone in order to maintain
> immutability - one may explicitly cast timestamp to timestamptz to assume a
> different timezone); for interval values, the total number of seconds in
> the interval"
Hmm, that's not really right either; it appears to imply that the epoch
calculation is timezone-aware, which it specifically isn't for date and
timestamp cases. An example (presuming US DST rules):
regression=# select extract(epoch from date '2020-03-09') - extract(epoch from date '2020-03-08');
?column?
----------
86400
(1 row)
regression=# select extract(epoch from timestamp '2020-03-09') - extract(epoch from timestamp '2020-03-08');
?column?
----------
86400
(1 row)
regression=# select extract(epoch from timestamptz '2020-03-09') - extract(epoch from timestamptz '2020-03-08');
?column?
----------
82800
(1 row)
The last case knows that there was a DST transition in between, the first
two don't take that into account. (You could argue that this is more a
property of the types' input conversion routines than of extract() itself,
but I think the point is valid anyway.)
Perhaps a better phrasing is "for date and timestamp values, the nominal
number of seconds since 1970-01-01 00:00:00, without regard to timezone
or daylight-savings rules".
regards, tom lane
Commits
-
Doc: improve explanation of EXTRACT(EPOCH) for timestamp without tz.
- f70e8997bc0d 10.16 landed
- ae58189540bd 11.11 landed
- 5706c4871cbb 12.6 landed
- 4d3f03f42227 14.0 landed
- 4a4cad91dab7 9.5.25 landed
- 4750d92ce82f 13.2 landed
- 1cfdeda1bd1f 9.6.21 landed
-
Doc: spell out comparison behaviors for the date/time types.
- e3bfdf216166 12.6 landed
- d56ea24166e9 9.6.21 landed
- abb208bfa5f7 11.11 landed
- 7fe23c8bb5d2 9.5.25 landed
- 7ca285cc2b03 10.16 landed
- 624fd9e56b45 13.2 landed
- 319f4d54e82d 14.0 landed