pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: huhao0715@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #15388: time convert error when use AT TIME ZONE '+8'
Date: Mon, 17 Sep 2018 23:45:05 -0400
Message-ID: <20541.1537242305@sss.pgh.pa.us> (raw)
In-Reply-To: <153724095414.13490.12512426893930004410@wrigleys.postgresql.org>
References: <153724095414.13490.12512426893930004410@wrigleys.postgresql.org>

=?utf-8?q?PG_Bug_reporting_form?= <noreply@postgresql.org> writes:
> 1. What did you do?
> SET TIME ZONE 'utc';
> SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE '+8';

> 2. What did you expect to see?
>         timezone
> ------------------------
>  2001-02-16 12:38:40+00

You're apparently confused about the sign of time zone offsets.
In a POSIX-style zone name, which is what you have there, plus
means west of Greenwich; so this is the right answer:

> 3. What did you see instead?
>         timezone
> ------------------------
>  2001-02-17 04:38:40+00

See 

https://www.postgresql.org/docs/current/static/datatype-datetime.html#DATATYPE-TIMEZONES

notably the comment that

   Another issue to keep in mind is that in POSIX time zone names,
   positive offsets are used for locations west of Greenwich. Everywhere
   else, PostgreSQL follows the ISO-8601 convention that positive timezone
   offsets are east of Greenwich.

If you want to use the ISO sign convention, you can do it with an
interval-type zone specification:

regression=# SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE '+8:00'::interval;
        timezone        
------------------------
 2001-02-16 12:38:40+00
(1 row)

			regards, tom lane




view thread (4+ messages)  latest in thread

Message-ID: <20541.1537242305@sss.pgh.pa.us>
Permalink:  ../20541.1537242305@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/20541.1537242305@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, huhao0715@gmail.com
  Subject: Re: BUG #15388: time convert error when use AT TIME ZONE '+8'
  In-Reply-To: <20541.1537242305@sss.pgh.pa.us>
  References: <153724095414.13490.12512426893930004410@wrigleys.postgresql.org> <20541.1537242305@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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