Browse Source

fix(nocodb): wrap with parentheses for pg raw query

pull/5659/head
Wing-Kam Wong 2 years ago
parent
commit
2b3ca70db1
  1. 7
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 10
      packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

7
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;
}
}

10
packages/nocodb/src/db/formulav2/formulaQueryBuilderv2.ts

@ -553,10 +553,12 @@ async function _formulaQueryBuilder(
) {
aliasToColumn[col.id] = async (): Promise<any> => {
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 {

Loading…
Cancel
Save