Re: Implicit timezone conversion replicating from timestamp to timestamptz?

From: Peter Eisentraut <peter(dot)eisentraut(at)2ndquadrant(dot)com>
To: Jeremy Finzel <finzelj(at)gmail(dot)com>, pglogical-list(at)2ndquadrant(dot)com, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Implicit timezone conversion replicating from timestamp to timestamptz?
Date: 2019-01-25 10:44:43
Message-ID: 2bffea9b-5e0c-d954-119d-660db396f058@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 24/01/2019 21:57, Jeremy Finzel wrote:
> The source system has a timestamp stored "at time zone UTC", like this
> for 6:00pm Chicago time:
> 2019-01-24 20:00:00.000000
>
> I was *very surprised* to find that replicating above timestamp to
> timestamptz actually does so correctly, showing this value in my psql
> client on the subscriber:
> 2019-01-24 14:00:00.000000-06
>
> How does it know/why does it assume it knows that the time zone of the
> timestamp data type is UTC on the provider given that my clusters are at
> America/Chicago?

This only works by accident in pglogical because the binary
representations of both types are compatible in this sense. You're not
really supposed to do that.

> I would have actually expected an incorrect conversion
> of the data unless I set the timezone to UTC on the way in on the
> subscriber via a trigger.
>
> That is, I was expecting to see this:
> 2019-01-24 20:00:00.000000-06

This is what you get in built-in logical replication, because it goes
via textual representation.

To make it do what you actually wanted, set the time zone for the
subscription worker to UTC. The way to do that (could be easier) is to
create a separate user, use ALTER USER SET timezone = 'UTC', and create
the subscription as that user.

--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2019-01-25 11:09:27 Re: Tab completion for ALTER INDEX|TABLE ALTER COLUMN SET STATISTICS
Previous Message Peter Eisentraut 2019-01-25 10:38:45 Re: using expression syntax for partition bounds