From: | Francisco Olarte <folarte(at)peoplecall(dot)com> |
---|---|
To: | dafoer_x(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour |
Date: | 2022-01-14 11:30:54 |
Message-ID: | CA+bJJbxLHKPOd7RUFckQ+X14+Ob+Swnqonc2m65garJRHsqdEw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Fri, 14 Jan 2022 at 11:15, PG Bug reporting form
<noreply(at)postgresql(dot)org> wrote:
> Logged by: Error result returned in timestamp2timestamptz, expected to be off by one
...
> postgres=# set timezone to "PST8PDT";
..
> postgres=# select (timestamp '2021-03-14 02:00:00')::timestamptz;
> 2021-03-14 03:00:00-07
> postgres=# select (timestamp '2021-03-14 03:00:00')::timestamptz;
> 2021-03-14 03:00:00-07
You are playing around the DST changes, and timestamp must have unique
representations, for informal descriptions "time jumps from 2 to 3" is
fine, when dealing with real data you must decide if it jumps just
before or just after, it seems your expectations are wrong:
=> show time zone;
TimeZone
----------
PST8PDT
(1 row)
=> with a(hms) as (values
('01:59:59'),('02:00:00'),('02:00:01'),('02:59:59'),('03:00:00'),('03:00:01'))
, b as (select '2021-03-14 '||hms as f from a)
select f, f::timestamp, (f::timestamp)::timestamptz from b;
f | f | f
---------------------+---------------------+------------------------
2021-03-14 01:59:59 | 2021-03-14 01:59:59 | 2021-03-14 01:59:59-08
2021-03-14 02:00:00 | 2021-03-14 02:00:00 | 2021-03-14 03:00:00-07
2021-03-14 02:00:01 | 2021-03-14 02:00:01 | 2021-03-14 03:00:01-07
2021-03-14 02:59:59 | 2021-03-14 02:59:59 | 2021-03-14 03:59:59-07
2021-03-14 03:00:00 | 2021-03-14 03:00:00 | 2021-03-14 03:00:00-07
2021-03-14 03:00:01 | 2021-03-14 03:00:01 | 2021-03-14 03:00:01-07
(6 rows)
Local values do not exist in the (2-3) interval, so they are shifted,
but to cover the timestamp line without overlapping you need half-open
intervals, pg is choosing to use rigth-open, so 2:00 does not exist
but 3:00 does, they cannot both exist ( as normalized output, as input
both are valid, but internally they are stored the same way, time
jumps, pg has to choose a coherent offset to print them ).
Francisco Olarte.
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2022-01-14 15:24:52 | Re: BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour |
Previous Message | PG Bug reporting form | 2022-01-14 04:06:42 | BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour |