From: | Dana Burd <djburd(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #16797: EXTRACT(EPOCH FROM timestamp) is not using local timezone |
Date: | 2021-01-01 19:14:20 |
Message-ID: | CADYUPHMsqBMY_-+=ssJMgjQ=VQG=Zjm3Jvmq4Y5EFXZcCSPbKg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
That phrasing makes sense.
You're correct, it is a nominal value, even if there might be a perception
that the value aligns with assuming UTC.
It's definitely tricky. Prior to this thread, I would have expected the
following to be the equivalent. Now I'd prefer that the first wasn't even
an allowed operation without an explicit cast - but that ship has likely
sailed long ago.
# SET TIME ZONE 'EST5EDT'; select extract (epoch from '2020-03-09
00:00:00'::timestamp - '2020-03-08 0:00:00'::timestamptz);
date_part
-----------
82800
(1 row)
# SET TIME ZONE 'EST5EDT'; select extract (epoch from '2020-03-09
00:00:00'::timestamp) - extract (epoch from '2020-03-08
0:00:00'::timestamptz);
?column?
----------
68400
regards,
-dana
On Fri, Jan 1, 2021 at 12:18 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Dana Burd <djburd(at)gmail(dot)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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2021-01-01 20:54:20 | Re: BUG #16797: EXTRACT(EPOCH FROM timestamp) is not using local timezone |
Previous Message | Tom Lane | 2021-01-01 17:18:12 | Re: BUG #16797: EXTRACT(EPOCH FROM timestamp) is not using local timezone |