From 7bfbf308d40f583ae6e64283afb897d11357d32f Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 10 May 2023 17:07:41 +0800 Subject: [PATCH] fix(nocodb): handle timestampz for pg --- packages/nocodb/src/models/Model.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/nocodb/src/models/Model.ts b/packages/nocodb/src/models/Model.ts index 0d60abe431..4eb88b140a 100644 --- a/packages/nocodb/src/models/Model.ts +++ b/packages/nocodb/src/models/Model.ts @@ -477,10 +477,13 @@ export default class Model implements TableType { .utcOffset(d.getTimezoneOffset(), true) .format('YYYY-MM-DD HH:mm:ss'); } else if (isPg) { - val = dayjs - .utc(val) - .utcOffset(d.getTimezoneOffset(), true) - .format('YYYY-MM-DD HH:mm:ssZ'); + if (col.dt !== 'timestamp with time zone') { + // e.g. 2023-05-10T08:49:32.000Z -> 2023-05-10 08:49:32-08:00 + val = dayjs + .utc(val) + .utcOffset(d.getTimezoneOffset(), true) + .format('YYYY-MM-DD HH:mm:ssZ'); + } } else if (isMssql) { val = dayjs .utc(val) @@ -492,6 +495,9 @@ export default class Model implements TableType { if (isMySQL) { // convert to utc val = dayjs(val).utc().format('YYYY-MM-DD HH:mm:ss'); + } else if (isPg) { + // convert to utc + val = dayjs(val).utc().format('YYYY-MM-DD HH:mm:ssZ'); } else { // keep it as it is val = dayjs(val).format('YYYY-MM-DD HH:mm:ssZ');