diff --git a/drift/lib/src/runtime/query_builder/expressions/aggregate.dart b/drift/lib/src/runtime/query_builder/expressions/aggregate.dart
index b999d898..5569396e 100644
--- a/drift/lib/src/runtime/query_builder/expressions/aggregate.dart
+++ b/drift/lib/src/runtime/query_builder/expressions/aggregate.dart
@@ -51,6 +51,12 @@ extension BaseAggregate
on Expression {
}) {
const sqliteDefaultSeparator = ',';
+ // Distinct aggregates can only have one argument
+ if (distinct && separator != sqliteDefaultSeparator) {
+ throw ArgumentError(
+ 'Cannot use groupConcat with distinct: true and a custom serparator');
+ }
+
return _AggregateExpression(
'GROUP_CONCAT',
[
diff --git a/drift/test/database/expressions/aggregate_test.dart b/drift/test/database/expressions/aggregate_test.dart
index ed751777..695443a1 100644
--- a/drift/test/database/expressions/aggregate_test.dart
+++ b/drift/test/database/expressions/aggregate_test.dart
@@ -83,21 +83,6 @@ void main() {
expect(foo.groupConcat(distinct: true),
generates('GROUP_CONCAT(DISTINCT foo)', isEmpty));
- expect(foo.groupConcat(distinct: true, separator: ' and '),
- generates('GROUP_CONCAT(DISTINCT foo, ?)', [' and ']));
-
- expect(
- foo.groupConcat(
- distinct: true,
- separator: ' and ',
- filter: foo.isSmallerThan(const Variable(3)),
- ),
- generates(
- 'GROUP_CONCAT(DISTINCT foo, ?) FILTER (WHERE foo < ?)',
- [' and ', 3],
- ),
- );
-
expect(
foo.groupConcat(
distinct: true,
@@ -109,5 +94,19 @@ void main() {
),
);
});
+
+ test('does not allow distinct with a custom separator', () {
+ expect(() => foo.groupConcat(distinct: true, separator: ' and '),
+ throwsArgumentError);
+
+ expect(
+ () => foo.groupConcat(
+ distinct: true,
+ separator: ' and ',
+ filter: foo.isSmallerThan(const Variable(3)),
+ ),
+ throwsArgumentError,
+ );
+ });
});
}