Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g26wv-0006p3-Sm for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Sep 2018 03:45:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g26wt-0001A1-8h for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Sep 2018 03:45:15 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g26ws-00019m-VT for pgsql-bugs@lists.postgresql.org; Tue, 18 Sep 2018 03:45:15 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g26wm-0005vg-6g for pgsql-bugs@lists.postgresql.org; Tue, 18 Sep 2018 03:45:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w8I3j54v020542; Mon, 17 Sep 2018 23:45:05 -0400 From: Tom Lane To: huhao0715@gmail.com cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15388: time convert error when use AT TIME ZONE '+8' In-reply-to: <153724095414.13490.12512426893930004410@wrigleys.postgresql.org> References: <153724095414.13490.12512426893930004410@wrigleys.postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Tue, 18 Sep 2018 03:22:34 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20540.1537242305.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 17 Sep 2018 23:45:05 -0400 Message-ID: <20541.1537242305@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =3D?utf-8?q?PG_Bug_reporting_form?=3D 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#DATA= TYPE-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=3D# 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