From: Ilya Anfimov <ilan@tzirechnoy.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Tools to convert timestamp data to another time zone in PostgreSQL
Date: Tue, 14 Jun 2022 09:53:17 +0300
Message-ID: <20220614065317.GA2493248@azor.tzirechnoy.ru> (raw)
In-Reply-To: <YT2PR01MB8805F27482999B87C1B94407E5AB9@YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM>
References: <YT2PR01MB8805F27482999B87C1B94407E5AB9@YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM>
On Mon, Jun 13, 2022 at 09:52:00PM +0000, Joel Rabinovitch wrote:
> Hi,
>
>
>
> We have recently modified our application to work with PostgreSQL
> databases and schemas. We also support Oracle and SQL Server Databases.
[skipped]
>
> As a result, we have hit an issue where we need to convert data in
> timestamp columns in existing records to reflect that the time is in UTC.
> The timezone is not specified in our timestamp columns (i.e. they are
> defined as timezone without time zone). We need to do this for
btw, it's not specified in timestamptz either.
timestamptz always stores time in UTC microseconds, and displays
it in timezone according to the session settings.
> interoperability between the database engines we support.
It's better to use timestamptz type
https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_timestamp_.28without_time_zone.29
and I think it's a good time to do that change.
[skipped]
Setting timezone in session to 'America/New_York' and converting
column to timestamptz should do it fine
set timezone = 'America/New_York';
ALTER TABLE <tablename> ALTER COLUMN create_stamp TYPE timestamptz;
should do it just fine (on a reasonably sized tables).
Other possibilities, like creating a new column and renaming it
after the proper feel in, are possible.
>
> set create_stamp = (create_stamp at time zone 'America/New_York' at
> time zone 'UTC')
>
> where client_code = 'HOANA';
>
>
>
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ilan@tzirechnoy.com
Subject: Re: Tools to convert timestamp data to another time zone in PostgreSQL
In-Reply-To: <20220614065317.GA2493248@azor.tzirechnoy.ru>
References: <YT2PR01MB8805F27482999B87C1B94407E5AB9@YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM> <20220614065317.GA2493248@azor.tzirechnoy.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox