Allow grouping by FastPrimaryKeyExpression

This commit is contained in:
Gwendal Roué committed 2020-07-01 21:24:27 +02:00
1 parent 2201026ce8
commit a328faa834
1 file changed
+14 -5
@@ -500,6 +500,20 @@ struct SQLQueryGenerator: Refinable {
return .none
}
// Grouping something which is not a table: assume non unique grouping.
guard case let .table(tableName: tableName, alias: alias) = relation.source else {
return .nonUnique
}
// FastPrimaryKeyExpression?
for expression in groupExpressions {
if
let column = expression as? QualifiedFastPrimaryKeyExpression,
column.alias == alias {
return .unique
}
}
// Grouping by something which is not a column: assume non
// unique grouping.
// SELECT * FROM player GROUP BY (score + bonus)
@@ -508,11 +522,6 @@ struct SQLQueryGenerator: Refinable {
return .nonUnique
}
// Grouping something which is not a table: assume non unique grouping.
guard case let .table(tableName: tableName, alias: alias) = relation.source else {
return .nonUnique
}
// Grouping by some column(s) which do not come from the main table:
// assume non unique grouping.
// SELECT * FROM player JOIN team ... GROUP BY team.id