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: djburd@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2020-12-30T19:01:42Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> EXTRACT(EPOCH FROM timestamp) should be using the local timezone
No, type timestamp is explicitly *not* timezone aware. If you use
timestamptz (a/k/a timestamp with time zone) you will get the
answer you want.
> -- Expected results (seen from PostgreSQL 9.1.11):
> # SET TIME ZONE 'EST5EDT'; select extract(epoch from ('01/01/1970
> 00:00:00'::timestamp));
This was a bug, cf 9.2.0 release notes [1]:
Make EXTRACT(EPOCH FROM timestamp without time zone) measure the epoch
from local midnight, not UTC midnight (Tom Lane)
This change reverts an ill-considered change made in release 7.3.
Measuring from UTC midnight was inconsistent because it made the
result dependent on the timezone setting, which computations for
timestamp without time zone should not be. The previous behavior
remains available by casting the input value to timestamp with time
zone.
regards, tom lane
[1] https://www.postgresql.org/docs/release/9.2.0/
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