From: Joel Rabinovitch <Joel.Rabinovitch@tecsys.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Tools to convert timestamp data to another time zone in PostgreSQL
Date: Mon, 13 Jun 2022 21:52:00 +0000
Message-ID: <YT2PR01MB8805F27482999B87C1B94407E5AB9@YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM> (raw)
Hi,
We have recently modified our application to work with PostgreSQL databases and schemas. We also support Oracle and SQL Server Databases.
Along with adding support for PostgreSQL, we have upgraded our infrastructure such that all environments are configured to use the UTC time zone. Previously, the environments were configured to use the time zone where the database server and application server were installed.
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 interoperability between the database engines we support.
After a bit of searching, we found we can write an SQL similar to the one below to do the conversion:
update client
set create_stamp = (create_stamp at time zone 'America/New_York' at time zone 'UTC')
where client_code = 'HOANA';
This does work correctly. However, we have some limitations in terms using SQL statements like this.
- We would need to identify the timestamp columns that would be affected across many tables and multiple schemas.
- We also store date-only information in timestamp without time zone columns. This was done as a result of migrating our application from Oracle where the DATE data type was used at the time (Oracle now supports timestamp columns).
I was wondering if you are aware of any open source and/or commercial tools that could allow us to easily identify the affected columns, exclude columns if necessary, and apply the necessary conversion. If not, we would have to write a utility that does this for us, which could be a lengthy process.
Thanks,
Joel
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: Joel.Rabinovitch@tecsys.com
Subject: Re: Tools to convert timestamp data to another time zone in PostgreSQL
In-Reply-To: <YT2PR01MB8805F27482999B87C1B94407E5AB9@YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM>
References: <YT2PR01MB8805F27482999B87C1B94407E5AB9@YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM>
* 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