From 2b3ca70db1631cded0b9a46ed7a12cc07d41086c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Thu, 18 May 2023 11:07:18 +0800 Subject: [PATCH] fix(nocodb): wrap with parentheses for pg raw query --- packages/nocodb/src/db/BaseModelSqlv2.ts | 7 ++++--- .../nocodb/src/db/formulav2/formulaQueryBuilderv2.ts | 10 ++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index b836a56460..a50534be70 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -1635,15 +1635,16 @@ class BaseModelSqlv2 { } else if (this.isPg) { // if there is no timezone info, convert it to UTC if (column.dt !== 'timestamp with time zone') { - res[sanitize(column.title || column.column_name)] = - this.dbDriver.raw( + res[sanitize(column.title || column.column_name)] = this.dbDriver + .raw( `?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`, [ `${sanitize(alias || this.model.table_name)}.${ column.column_name }`, ], - ); + ) + .wrap('(', ')'); break; } } diff --git a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts index 312eb169ee..a347455c3f 100644 --- a/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts +++ b/packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts @@ -553,10 +553,12 @@ async function _formulaQueryBuilder( ) { aliasToColumn[col.id] = async (): Promise => { return { - builder: knex.raw( - `?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`, - [col.column_name], - ), + builder: knex + .raw( + `?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`, + [col.column_name], + ) + .wrap('(', ')'), }; }; } else {