pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour
3+ messages / 3 participants
[nested] [flat]

* BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour
@ 2022-01-14 04:06  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2022-01-14 04:06 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: dafoer_x@163.com

The following bug has been logged on the website:

Bug reference:      17366
Logged by:          Error result returned in timestamp2timestamptz, expected to be off by one
hour
Email address:      dafoer_x@163.com
PostgreSQL version: 14.1
Operating system:   REL_14_STABLE
Description:        

For REL_14_STABLE
git log ad5b6f248ab288c3252d8122d12a1eb410d4a0b6

e.g.
postgres=# set timezone to "PST8PDT";
SET
postgres=# select * from pg_timezone_names where name = 'PST8PDT';
  name   | abbrev | utc_offset | is_dst 
---------+--------+------------+--------
 PST8PDT | PST    | -08:00:00  | f
(1 row)

postgres=# select (timestamp '2021-03-14 02:00:00')::timestamptz;
      timestamptz       
------------------------
 2021-03-14 03:00:00-07
(1 row)

postgres=# select (timestamp '2021-03-14 03:00:00')::timestamptz;
      timestamptz       
------------------------
 2021-03-14 03:00:00-07
(1 row)


expected:
postgres=# select (timestamp '2021-03-14 02:00:00')::timestamptz;
2021-03-14 02:00:00-07



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour
@ 2022-01-14 11:30  Francisco Olarte <folarte@peoplecall.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 3+ messages in thread

From: Francisco Olarte @ 2022-01-14 11:30 UTC (permalink / raw)
  To: dafoer_x@163.com; pgsql-bugs@lists.postgresql.org

On Fri, 14 Jan 2022 at 11:15, PG Bug reporting form
<noreply@postgresql.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.





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour
@ 2022-01-14 15:24  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Francisco Olarte <folarte@peoplecall.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2022-01-14 15:24 UTC (permalink / raw)
  To: Francisco Olarte <folarte@peoplecall.com>; +Cc: dafoer_x@163.com; pgsql-bugs@lists.postgresql.org

Francisco Olarte <folarte@peoplecall.com> writes:
> On Fri, 14 Jan 2022 at 11:15, PG Bug reporting form
> <noreply@postgresql.org> wrote:
>> 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:

Yeah.  See

https://www.postgresql.org/docs/devel/datetime-invalid-input.html

(I'm pointing you to the devel version of that page because it
contains a correction that hasn't yet propagated into the other
versions)

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-01-14 15:24 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14 04:06 BUG #17366: Error result returned in timestamp2timestamptz, expected to be off by one hour PG Bug reporting form <noreply@postgresql.org>
2022-01-14 11:30 ` Francisco Olarte <folarte@peoplecall.com>
2022-01-14 15:24   ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox