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 1o0ryl-0008Vm-RA for pgsql-general@arkaria.postgresql.org; Mon, 13 Jun 2022 21:52:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1o0ryk-0007RM-FX for pgsql-general@arkaria.postgresql.org; Mon, 13 Jun 2022 21:52:10 +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 1o0ryj-0007Qy-Sy for pgsql-general@lists.postgresql.org; Mon, 13 Jun 2022 21:52:10 +0000 Received: from mail-qb1can01on2063.outbound.protection.outlook.com ([40.107.66.63] helo=CAN01-QB1-obe.outbound.protection.outlook.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o0ryf-0005o9-Sb for pgsql-general@lists.postgresql.org; Mon, 13 Jun 2022 21:52:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AHkff3LBbNxZv+XbU+dn8sXZHBFvj+LLVCzFYCjVm5+HDDn9Qv3TJp1mbHTwc0yctS9R8XXAqX7Cyr5EB3xv4JOfEGMSh7M9sUC8RscWmHlDJaOZYYoN/WiI73bYulQnpuEkE3uWtH2xaLvwOGoQiXTQYAM8UtdItDzFkOGfDAItaXaTxbrQUy3+rgPTlC1+SDLVDZRss8UhSf86Hj5I03Rh2xCiRi1PxYpVuuK9uGS2jVh+ZD3FLrUSVaqgK8K3IneCkJF/tJaONiBvXT95sWkTO3amKQbNno0J9oaY+I6gZV8iI4yOYOoWguodjZMZLaAc2dVYO+Hbk0fVaT8y7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=WD9WKves8jlcyskKISeU/jB+cO+r6pNaWELRCFTjFpo=; b=iRQIq7ZSfwUPPjPUD+to80ijaPlzOmvFsX+BC2jaaUNJ1eL+K8o4aDmOKogh3MtPHDqcv9lSBc05/EZqN8H4xGHQYFwrkU1afDC2CJQzNgTDLwvV15pxkSr5itu0XFDA8K1PAk3/hkDqTc4d24Asb0R4Ff6/CYtctBNlVvp91XrFcl+QZhePUMySy5kefmmK1WGR4Uufd/LoGc4BizjBcHvfCiH2AOaCRwjkgrxl72Y2at4dhLh6Y8fz/LUbP+6sZLrRhl5Lmyi84e13a0PFTSuBRLZDYpb3C2DiunNxkBSyGDeQwldTAY67dW/6wKU3GgtNePVv3aK7+iIZ2+wCVg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=tecsys.com; dmarc=pass action=none header.from=tecsys.com; dkim=pass header.d=tecsys.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tecsys4.onmicrosoft.com; s=selector2-tecsys4-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WD9WKves8jlcyskKISeU/jB+cO+r6pNaWELRCFTjFpo=; b=Ny1CJ6Rnj8XnkZxTvBizupupRcDqcZZ5pX+r40UPA+XWTfBcMp/teX5UwntxPVMEEjtPL0XuaNcIURW/fvVLDDqsD6+kM0tsFLW+7rFZ0T4V28bPTNmt7O0h1Tn/5A5GXt5d3Hi/fOi/FvJx9q66WbfGX9eyFxdR2YBkT4xQow0= Received: from YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:b8::19) by YTBPR01MB2672.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:1d::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5332.13; Mon, 13 Jun 2022 21:52:00 +0000 Received: from YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM ([fe80::1174:bfe5:d323:d3f6]) by YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM ([fe80::1174:bfe5:d323:d3f6%3]) with mapi id 15.20.5332.020; Mon, 13 Jun 2022 21:52:00 +0000 From: Joel Rabinovitch To: "pgsql-general@lists.postgresql.org" Subject: Tools to convert timestamp data to another time zone in PostgreSQL Thread-Topic: Tools to convert timestamp data to another time zone in PostgreSQL Thread-Index: Adh/b854piF145LSQPChSBlz2ijZgw== Date: Mon, 13 Jun 2022 21:52:00 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=tecsys.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c09dfde8-4209-46a5-45e9-08da4d86f1e9 x-ms-traffictypediagnostic: YTBPR01MB2672:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xUCzlSUeD69McGC7xcCRC1SKEkcTNc/oalqJucx6cIueFEm9LcSuPRgBfjaKVuUguWCmp40jWXxu01VcSNowYEPLNmCrLi08hdhFOVl4Q1IFf9BFZwZIACzDtfEpeayypYeflaHXxG50A/WvX8jSI9dBYFTIALN069I8qDatArYwfGD3N8h0UlSa8mswDmi5JC1srdLpEed9199XCY3/AFy71HnBiZDB3vrZW38r3oS/4vDd0SEoY3vpYxfewiPtjQ8nyC+6HrzurYL9roUckYo71UZl6k+jCAduZv01gOaQXCo+tmSd5YYfXh/KQz41rUGQhcjeaA7ggbQKlcBqlrzyvItnB1istufGGPKuqZ9oLB3qhBOjTU+N/zrHRAxk8vFDBpQmGf+NDR9EnXnN5Uxb4f5s89LSZIbR7nIxQZobhLGqR/PSAOYpCFjwpIMl5JQG0JtRMw925I5PfC9SocKE+u6T3oUxEiUwFNEmzS8l6RyQTL/r0kzl1VZ+ddpnYFx88iTm6btC3M+hL7gzfb0X7sVzZWNosU9y+XuAwNoK9y7w+JMtQj9iq7hlxoERRehYCPWfavvTP/MNiIpA92gOqxhk/o3eBkBCUzgaSyZ3grlcp2RJqQMlDjtLWFSFfJr8LIhhmo/1qlUD14U9tYUmjlR3fTua9MDj8xJRMBjifHfmUarViCUwXJR0tas1ccBSyAV8R+e4Xn6GRqb8RQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(83380400001)(6506007)(9686003)(7696005)(6916009)(26005)(316002)(186003)(9326002)(2906002)(55016003)(33656002)(5660300002)(52536014)(64756008)(66446008)(508600001)(8936002)(86362001)(76116006)(71200400001)(122000001)(38070700005)(38100700002)(66946007)(66476007)(8676002)(66556008);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?9/WPC3z1bRkoLWfmMeQirIlB36Ui15rDzgQ88NnHUpozGw1Ln11LiGQaGSXg?= =?us-ascii?Q?3XEvZ0IaQ2JzTqrf6tkXyH92Rwx8Uyn7PiCxoLl6og+xN6RKhHGCj1B2tINS?= =?us-ascii?Q?AO7gMw81MiJ9biZ38R3dWR1oBWGMRVZDjdK9qDYEQSV1INCFkePwQpGt1m0B?= =?us-ascii?Q?yQa+ItiilV+pqFwMxH1oo0lWODxHur+B3kZFgMxyb2L8dK1qr+NXUPwj00bm?= =?us-ascii?Q?1y0QvMuTjgJ19cIBz9QdH1EPtdn4im7ovEky+RF8Fa+0jnl8MXM+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dppAVdOExLbSKj1ZwY3fv9rUWQL51jx5FXNxXzDD?= =?us-ascii?Q?79HvBEMd1NE8oF7fIRIYENTXd2pt5ofbz1x5MyMxVHBWC0RJijqddBSB0yGK?= =?us-ascii?Q?f0HoPGz3/88xNnRyt1sMGwvTYITNuSq7JrRfbhMW0Lg+NfT5UbjO4NRBfpf1?= =?us-ascii?Q?n3HPYldcdM2d+34VOS19bI70wlSxgR4LlXGwlnYJw0JfbaLIAAjFzxnCrvPk?= =?us-ascii?Q?m+V8fuHhzW7eCuz/HEP/mWmOGiYl06wd1PHNc1dh5NraUjzExFOoES63l0A9?= =?us-ascii?Q?cM2P7ypEVS8Bh7UvPS6litCPSeP/VCrUAV1jr0km4r0cj+N6MBl+bCN5AcBf?= =?us-ascii?Q?onxySkR2Q2spkh6pDQHgaLvdYEH2msJ4djb0iEvXaj9EjBAwObYTfGnf2rvi?= =?us-ascii?Q?qxd/sS/U+drJkClhUqYz7pKx6K1yPd0RI255q2Fuv5M7awc1zdr2JIAPMDfa?= =?us-ascii?Q?k8ixr7K6YcNZGltgGXnPOIU/vkWWq2DFauBcYVPs2i9zKlMftBFSiDNN9J+g?= =?us-ascii?Q?XfupraVRqCyX/8wNKXd6OF86DhoLxj68nuJkfFOlf5V52lf/Sh/BvDyWdHGQ?= =?us-ascii?Q?wU88cO6tXQnUQY6v2Y7VwvACWlxHjKU=3D?= Content-Type: multipart/alternative; boundary="_000_YT2PR01MB8805F27482999B87C1B94407E5AB9YT2PR01MB8805CANP_" MIME-Version: 1.0 X-OriginatorOrg: tecsys.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: YT2PR01MB8805.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: c09dfde8-4209-46a5-45e9-08da4d86f1e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 13 Jun 2022 21:52:00.5587 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46ced3a4-6065-4b72-9d5e-79ecf873728d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: TgHQReEp7eOqvuOrv7QPytcM4l8NYBUMp/lD+u1kOaSfiC+ZpLKJrqVlcvasvvNo2bODc1w2JvHoLzxBIbuiWut7VJpowaHsJBv6pYMIT8A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YTBPR01MB2672 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --_000_YT2PR01MB8805F27482999B87C1B94407E5AB9YT2PR01MB8805CANP_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 infrastructu= re such that all environments are configured to use the UTC time zone. Prev= iously, the environments were configured to use the time zone where the dat= abase server and application server were installed. As a result, we have hit an issue where we need to convert data in timestam= p columns in existing records to reflect that the time is in UTC. The timez= one is not specified in our timestamp columns (i.e. they are defined as tim= ezone without time zone). We need to do this for interoperability between t= he database engines we support. After a bit of searching, we found we can write an SQL similar to the one b= elow to do the conversion: update client set create_stamp =3D (create_stamp at time zone 'America/New_York' at ti= me zone 'UTC') where client_code =3D '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 ac= ross many tables and multiple schemas. - We also store date-only information in timestamp without time zone column= s. 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 col= umns). 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 colum= ns 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 --_000_YT2PR01MB8805F27482999B87C1B94407E5AB9YT2PR01MB8805CANP_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi,

 

We have recently modified our application to work wi= th PostgreSQL databases and schemas. We also support Oracle and SQL Server = Databases.

 

Along with adding support for PostgreSQL, we have up= graded 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 c= onvert data in timestamp columns in existing records to reflect that the ti= me 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 e= ngines we support.

 

After a bit of searching, we found we can write an S= QL similar to the one below to do the conversion:

 

update client

   set create_stamp =3D (create_stamp at t= ime zone 'America/New_York' at time zone 'UTC')

where client_code =3D 'HOANA';

 

This does work correctly. However, we have some limi= tations in terms using SQL statements like this.

 

- We would need to identify the timestamp columns th= at would be affected across many tables and multiple schemas.

- We also store date-only information in timestamp w= ithout time zone columns. This was done as a result of migrating our applic= ation 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

--_000_YT2PR01MB8805F27482999B87C1B94407E5AB9YT2PR01MB8805CANP_--