Re: Converting to UTC multiple times converts back to local time zone - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: Converting to UTC multiple times converts back to local time zone
Date
Msg-id CAKFQuwYeHxefXOWmF_fXOM=MfR=QOz=Uas-HNz5_fA=R-koUfw@mail.gmail.com
Whole thread Raw
In response to Converting to UTC multiple times converts back to local time zone  (Gary Bernhardt <gary.bernhardt@gmail.com>)
Responses Re: Converting to UTC multiple times converts back to local time zone  (Gary Bernhardt <gary.bernhardt@gmail.com>)
List pgsql-bugs
On Mon, Jun 25, 2018 at 4:47 PM, Gary Bernhardt <gary.bernhardt@gmail.com> wrote:

testdb=# select (now() at time zone 'utc') at time zone 'utc';
2018-06-25 16:43:03.200762-07
 
I'd expect "converting" a UTC timestamp to UTC would keep it in UTC. Am I missing something?
Not a bug - the behavior is documented here:


Specifically, for the point-in-time types whenever one type is deferenced using AT TIME ZONE the alternate type is output.

SELECT pg_typeof(now()); -- timestamp with time zone (timestamptz)
SELECT pg_typeof(now() at time zone 'utc'); -- timestamp without time zone​ (timestamp)

I'll agree that this was a surprising finding for me too, but in the overall scheme of how PostgreSQL works, and other features it provides (e.g., TimeZone GUC and to_char()) it fits.

David J.
P.S. All timestamptz values are stored at UTC without knowledge of the original timezone.

pgsql-bugs by date:

Previous
From: Gary Bernhardt
Date:
Subject: Converting to UTC multiple times converts back to local time zone
Next
From: Gary Bernhardt
Date:
Subject: Re: Converting to UTC multiple times converts back to local time zone