From ac0c78b78365f572f61a855d73ee9f888a961015 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 8 Dec 2022 18:36:50 +0800 Subject: [PATCH] feat(nocodb): add missing hour logic and correct milliseconds sql --- .../lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts index 60c0e122c4..72ee49bcfa 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts @@ -67,6 +67,9 @@ const pg = { sql = `EXTRACT(EPOCH from (${datetime_expr1}::TIMESTAMP - ${datetime_expr2}::TIMESTAMP))::INTEGER / 60`; break; case 'milliseconds': + sql = `EXTRACT(EPOCH from (${datetime_expr1}::TIMESTAMP - ${datetime_expr2}::TIMESTAMP))::INTEGER * 1000`; + break; + case 'hour': sql = `EXTRACT(EPOCH from (${datetime_expr1}::TIMESTAMP - ${datetime_expr2}::TIMESTAMP))::INTEGER / 3600`; break; case 'week': @@ -83,9 +86,9 @@ const pg = { break; case 'quarter': sql = `((EXTRACT(QUARTER FROM ${datetime_expr1}::TIMESTAMP) + - DATE_PART('year', AGE(${datetime_expr1},'1900/01/01')) * 4) - 1) - + DATE_PART('year', AGE(${datetime_expr1}, '1900/01/01')) * 4) - 1) - ((EXTRACT(QUARTER FROM ${datetime_expr2}::TIMESTAMP) + - DATE_PART('year', AGE(${datetime_expr2},'1900/01/01')) * 4) - 1)`; + DATE_PART('year', AGE(${datetime_expr2}, '1900/01/01')) * 4) - 1)`; break; case 'year': sql = `DATE_PART('year', ${datetime_expr1}::TIMESTAMP) - DATE_PART('year', ${datetime_expr2}::TIMESTAMP)`;