groupConcat method
- {String separator = ',',
- bool distinct = false,
- Expression<
bool> ? filter}
Returns the concatenation of all non-null values in the current group,
joined by the separator
.
The order of the concatenated elements is arbitrary. If no non-null values
exist in the group, NULL
is returned.
If distinct
is set to true
(it defaults to false
), duplicate
elements are not added to the combined string twice.
To only consider rows matching a predicate, you can set the optional
filter
. Note that filter
is only available from sqlite 3.30, released on
2019-10-04. Most devices will use an older sqlite version.
See also:
- the sqlite documentation: https://www.sqlite.org/lang_aggfunc.html#groupconcat
- the conceptually similar Iterable.join
Implementation
Expression<String> groupConcat({
String separator = ',',
bool distinct = false,
Expression<bool>? filter,
}) {
const sqliteDefaultSeparator = ',';
// Distinct aggregates can only have one argument
if (distinct && separator != sqliteDefaultSeparator) {
throw ArgumentError(
'Cannot use groupConcat with distinct: true and a custom separator');
}
return _AggregateExpression(
'GROUP_CONCAT',
[
this,
if (separator != sqliteDefaultSeparator) Variable.withString(separator)
],
distinct: distinct,
filter: filter,
);
}