From f269649efd730592f86ce62f7f8f921f90c65fef Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sun, 30 Oct 2022 12:56:26 +0800 Subject: [PATCH] fix(nocodb): handle type in round function in postgres --- .../lib/db/sql-data-mapper/lib/sql/functionMappings/pg.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 3dad58ef9c..f24ec33598 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 @@ -9,7 +9,6 @@ const pg = { MIN: 'least', MAX: 'greatest', CEILING: 'ceil', - ROUND: 'round', POWER: 'pow', SQRT: 'sqrt', SEARCH: (args: MapFnArgs) => { @@ -35,6 +34,13 @@ const pg = { .raw(`CAST(${fn(pt.arguments[0])} as DOUBLE PRECISION)${colAlias}`) .wrap('(', ')'); }, + ROUND: ({ fn, knex, pt, colAlias }: MapFnArgs) => { + return knex.raw( + `ROUND((${fn(pt.arguments[0])})::numeric, ${ + pt?.arguments[1] ? fn(pt.arguments[1]) : 0 + }) ${colAlias}` + ); + }, DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => { return knex.raw( `${fn(pt.arguments[0])} + (${fn(pt.arguments[1])} ||