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 1fXbDH-0002Vf-VZ for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Jun 2018 23:48:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fXbDF-0000SZ-V0 for pgsql-bugs@arkaria.postgresql.org; Mon, 25 Jun 2018 23:48:01 +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.89) (envelope-from ) id 1fXbDF-0000SS-4R for pgsql-bugs@lists.postgresql.org; Mon, 25 Jun 2018 23:48:01 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fXbDB-0000Qp-4O for pgsql-bugs@lists.postgresql.org; Mon, 25 Jun 2018 23:48:00 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 2692921C44 for ; Mon, 25 Jun 2018 19:47:54 -0400 (EDT) Received: from web4 ([10.202.2.214]) by compute1.internal (MEProxy); Mon, 25 Jun 2018 19:47:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=5PKTinlklZik8AM0X13+155AW7B1i QRx/+UF/63pz7k=; b=C95RJfRwqwg4uOX4XdvqSJpiyAeIW6U/4p4o+GoflRopx iu+8z4OinubZsRiU7jeaNWQZW+UT7r0GRd6OYdk7mMgahx9sgiQxy1F5fQ1+Xz78 MncoLyORL400fR2SIC5172krhSv/HLYdLUazu/PGE7e8fhk/Ml4MgFlFDYsMDenJ s+D8YcUG/4wVOfxyCgihP8iXp5acffohixf7BcFgbO6PbNu4rZDgtj2Xd+K+Bt7j GpNW3Fvvt1n5sgEAExqNZ4Tkm0KCZ3oeGsBQ6CUOqpKb2cUq6qeftIhCPE8Gl7jf /h+laNS5uaZhkCZu+Vs032/wVlqVuM1W79Avm7SzA== X-ME-Proxy: X-ME-Sender: Received: by mailuser.nyi.internal (Postfix, from userid 99) id EBB36BA4CF; Mon, 25 Jun 2018 19:47:53 -0400 (EDT) Message-Id: <1529970473.36096.1420218376.3C13DF11@webmail.messagingengine.com> From: Gary Bernhardt To: pgsql-bugs@lists.postgresql.org MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: multipart/alternative; boundary="_----------=_1529970473360962" X-Mailer: MessagingEngine.com Webmail Interface - ajax-0d8ea36c Subject: Converting to UTC multiple times converts back to local time zone Date: Mon, 25 Jun 2018 16:47:53 -0700 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --_----------=_1529970473360962 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" now() is local, as I expect: testdb=# select now(); 2018-06-25 16:41:28.037072-07 And converting to UTC does convert to UTC: testdb=# select now() at time zone 'utc'; 2018-06-25 23:41:23.700795 But converting that timestamp to UTC a second time converts back to local: testdb=# select (now() at time zone 'utc') at time zone 'utc'; 2018-06-25 16:43:03.200762-07 This seems to happen regardless of where the UTC timestamp comes from. Here's the same thing done with a subquery: testdb=# select (ts at time zone 'utc') from (select now() at time zone 'utc' as ts) as t1;2018-06-25 16:44:05.219322-07 This seems very wrong to me. But this also seems like something that would have been exercised many, many times in the wild. I'd expect "converting" a UTC timestamp to UTC would keep it in UTC. Am I missing something? --_----------=_1529970473360962 Content-Transfer-Encoding: 7bit Content-Type: text/html; charset="utf-8"
now() is local, as I expect:

testdb=# select now();
2018-06-25 16:41:28.037072-07

And converting to UTC does convert to UTC:

testdb=# select now() at time zone 'utc';
2018-06-25 23:41:23.700795

But converting that timestamp to UTC a second time converts back to local:

testdb=# select (now() at time zone 'utc') at time zone 'utc';
2018-06-25 16:43:03.200762-07

This seems to happen regardless of where the UTC timestamp comes from. Here's the same thing done with a subquery:

testdb=# select (ts at time zone 'utc') from (select now() at time zone 'utc' as ts) as t1;
2018-06-25 16:44:05.219322-07

This seems very wrong to me. But this also seems like something that would have been exercised many, many times in the wild.

I'd expect "converting" a UTC timestamp to UTC would keep it in UTC. Am I missing something?
--_----------=_1529970473360962--