Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dBOEQ-0003GH-7m for pgsql-bugs@arkaria.postgresql.org; Thu, 18 May 2017 16:24:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dBOEP-0002vR-Qr for pgsql-bugs@arkaria.postgresql.org; Thu, 18 May 2017 16:24:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dBOEP-0002ts-7I for pgsql-bugs@postgresql.org; Thu, 18 May 2017 16:24:53 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dBOEM-0000HI-3O for pgsql-bugs@postgresql.org; Thu, 18 May 2017 16:24:52 +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 v4IGOlT5025206; Thu, 18 May 2017 12:24:47 -0400 From: Tom Lane To: tbrandys@webcellence.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14660: Conversion to UTC not properly computed In-reply-to: <20170518160916.29053.46920@wrigleys.postgresql.org> References: <20170518160916.29053.46920@wrigleys.postgresql.org> Comments: In-reply-to tbrandys@webcellence.com message dated "Thu, 18 May 2017 16:09:16 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25204.1495124687.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 18 May 2017 12:24:47 -0400 Message-ID: <25205.1495124687@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org tbrandys@webcellence.com writes: > vendita=3D# select now()::timestamp(0), now()::timestamp(0) with time zon= e, > timezone('utc', now()::timestamp(0)), timezone('utc', now()::timestamp(0) > with time zone); > now | now | timezone |= =20=20=20=20 > timezone > ---------------------+------------------------+------------------------+-= -------------------- > 2017-05-18 08:55:10 | 2017-05-18 08:55:10-07 | 2017-05-18 01:55:10-07 | > 2017-05-18 15:55:10 > (1 row) > vendita=3D# show timezone; > TimeZone > ------------ > US/Arizona > (1 row) > The computation where the assumed use of the local time zone should occur= is > incorrect (the third column). Looks fine to me. As per your first column, the result of now()::timestamp= (0) is '2017-05-18 08:55:10' (with no zone implied). timezone('utc', ...) converts that into a timestamptz assuming that it's UTC, that is the value is effectively '2017-05-18 08:55:10+00'. However, the timestamptz output function rotates that back to the current TimeZone zone for display purposes, so you see '2017-05-18 01:55:10-07' --- which is the same time instant, just in a different zone. I think perhaps what's confusing you is that PG's timestamptz values don't store a zone value but just a time instant, which is why timestamptz_out has to assume a zone to display in. That's not really per SQL spec, but changing it would be very difficult, so I'm not holding my breath waiting for it to happen. regards, tom lane --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs