Converting to UTC multiple times converts back to local time zone

From: Gary Bernhardt <gary(dot)bernhardt(at)gmail(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Converting to UTC multiple times converts back to local time zone
Date: 2018-06-25 23:47:53
Message-ID: 1529970473.36096.1420218376.3C13DF11@webmail.messagingengine.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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?

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G. Johnston 2018-06-26 00:20:28 Re: Converting to UTC multiple times converts back to local time zone
Previous Message csusza 2018-06-25 13:28:02 Re: Crashed libpq.dll in a multithreaded environment in case of SSL connection + callstack