Browse Source

fix: datetime group by corrections

pull/9013/head
Pranav C 5 months ago
parent
commit
25e648cb9c
  1. 42
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 16
      packages/nocodb/src/db/conditionV2.ts

42
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -1154,6 +1154,27 @@ class BaseModelSqlv2 {
groupBySelectors.push(column.id);
}
break;
case UITypes.CreatedTime:
case UITypes.LastModifiedTime:
case UITypes.DateTime:
{
const columnName = await getColumnName(
this.context,
column,
columns,
);
if (this.dbDriver.clientType() === 'pg') {
selectors.push(
this.dbDriver.raw('??::date as ??', [columnName, column.id]),
);
} else {
selectors.push(
this.dbDriver.raw('DATE(??) as ??', [columnName, column.id]),
);
}
groupBySelectors.push(column.id);
}
break;
default:
{
const columnName = await getColumnName(
@ -1396,6 +1417,27 @@ class BaseModelSqlv2 {
groupBySelectors.push(column.id);
}
break;
case UITypes.CreatedTime:
case UITypes.LastModifiedTime:
case UITypes.DateTime:
{
const columnName = await getColumnName(
this.context,
column,
columns,
);
if (this.dbDriver.clientType() === 'pg') {
selectors.push(
this.dbDriver.raw('??::date as ??', [columnName, column.id]),
);
} else {
selectors.push(
this.dbDriver.raw('DATE(??) as ??', [columnName, column.id]),
);
}
groupBySelectors.push(column.id);
}
break;
default:
{
const columnName = await getColumnName(

16
packages/nocodb/src/db/conditionV2.ts

@ -737,12 +737,7 @@ const parseConditionV2 = async (
column.ct === 'date' ||
column.ct === 'datetime'
) {
if (filter.groupby && column.ct !== 'date')
qb = qb.where(
knex.raw('?? = ?', [field, val.replace(/\+\d+:\d+$/, '')]),
);
else
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
} else {
// mysql is case-insensitive for strings, turn to case-sensitive
qb = qb.where(knex.raw('BINARY ?? = ?', [field, val]));
@ -759,14 +754,9 @@ const parseConditionV2 = async (
].includes(column.uidt)
) {
if (qb.client.config.client === 'pg') {
if (filter.groupby)
qb = qb.where(knex.raw('?? = ?', [field, val]));
else qb = qb.where(knex.raw('??::date = ?', [field, val]));
qb = qb.where(knex.raw('??::date = ?', [field, val]));
} else {
if (filter.groupby)
qb = qb.where(knex.raw('?? = ?', [field, val]));
else
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
qb = qb.where(knex.raw('DATE(??) = DATE(?)', [field, val]));
}
} else {
qb = qb.where(field, val);

Loading…
Cancel
Save