Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix: do the select wrapping in group-by since CTE can be part of insert query as well

Pranav C1a34eb7e7ee3
diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts
index 86911334b8..913f86d0ba 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2.ts
@@ -148,7 +148,6 @@ const ORDER_STEP_INCREMENT = 1;
const MAX_RECURSION_DEPTH = 2;
-const CTE_REGEX = /^(\(|)with/i;
const SELECT_REGEX = /^(\(|)select/i;
const INSERT_REGEX = /^(\(|)insert/i;
@@ -5059,8 +5058,6 @@ class BaseModelSqlv2 implements IBaseModelSqlV2 {
if (this.isPg || this.isSnowflake) {
return (await trx.raw(query))?.rows;
- } else if (CTE_REGEX.test(query)) {
- return await trx.from(trx.raw(query).wrap('(', ') __nc_alias'));
} else if (SELECT_REGEX.test(query)) {
return await trx.from(trx.raw(query).wrap('(', ') __nc_alias'));
} else if (this.isMySQL && INSERT_REGEX.test(query)) {
diff --git a/packages/nocodb/src/db/BaseModelSqlv2/group-by.ts b/packages/nocodb/src/db/BaseModelSqlv2/group-by.ts
index bcaa8d8199..1ca6bfbc4d 100644
--- a/packages/nocodb/src/db/BaseModelSqlv2/group-by.ts
+++ b/packages/nocodb/src/db/BaseModelSqlv2/group-by.ts
@@ -438,7 +438,11 @@ export const groupBy = (baseModel: IBaseModelSqlV2, logger: Logger) => {
}
}
- return await baseModel.execAndParse(outerQb);
+ return await baseModel.execAndParse(
+ baseModel.dbDriver.from(
+ baseModel.dbDriver.raw(outerQb).wrap('(', ') __nc_group_alias'),
+ ),
+ );
};
const count = async (args: {