}
currentSelect.setGroupQuery();
Expression r;
if (aggregateType == Aggregate.COUNT) {
if (readIf("*")) {
r = new Aggregate(Aggregate.COUNT_ALL, null, currentSelect, false);
} else {
boolean distinct = readIf("DISTINCT");
Expression on = readExpression();
if (on instanceof Wildcard && !distinct) {
// PostgreSQL compatibility: count(t.*)
r = new Aggregate(Aggregate.COUNT_ALL, null, currentSelect, false);
} else {
r = new Aggregate(Aggregate.COUNT, on, currentSelect, distinct);
}
}
} else if (aggregateType == Aggregate.GROUP_CONCAT) {
boolean distinct = readIf("DISTINCT");
Aggregate agg = new Aggregate(Aggregate.GROUP_CONCAT, readExpression(), currentSelect, distinct);
if (readIf("ORDER")) {
read("BY");
agg.setOrder(parseSimpleOrderList());
}
if (readIf("SEPARATOR")) {
agg.setSeparator(readExpression());
}
r = agg;
} else {
boolean distinct = readIf("DISTINCT");
r = new Aggregate(aggregateType, readExpression(), currentSelect, distinct);
}
read(")");
return r;
}