Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o10RU-000468-W6 for pgsql-general@arkaria.postgresql.org; Tue, 14 Jun 2022 06:54:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o10QV-0007vM-Jx for pgsql-general@arkaria.postgresql.org; Tue, 14 Jun 2022 06:53:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o10QV-0007vD-9Y for pgsql-general@lists.postgresql.org; Tue, 14 Jun 2022 06:53:23 +0000 Received: from carbon.misis.ru ([85.143.104.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o10QS-0004C0-6K for pgsql-general@lists.postgresql.org; Tue, 14 Jun 2022 06:53:22 +0000 Received: from mail.tzirechnoy.ru (unknown [10.1.250.11]) by carbon.misis.ru (Postfix) with ESMTP id 6A60A217B9 for ; Tue, 14 Jun 2022 09:53:18 +0300 (MSK) Received: by mail.tzirechnoy.ru (Postfix, from userid 1000) id D1EBEA42B1; Tue, 14 Jun 2022 09:53:17 +0300 (MSK) Date: Tue, 14 Jun 2022 09:53:17 +0300 From: Ilya Anfimov To: pgsql-general@lists.postgresql.org Subject: Re: Tools to convert timestamp data to another time zone in PostgreSQL Message-ID: <20220614065317.GA2493248@azor.tzirechnoy.ru> Mail-Followup-To: Ilya Anfimov , pgsql-general@lists.postgresql.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spamd-Result: default: False [0.00 / 15.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2] X-Rspamd-Queue-Id: 6A60A217B9 X-Rspamd-Server: carbon List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 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'; > > >