You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GROUP_CONCAT(x ORDER BY y) sorts by x, not by y #2658
GROUP_CONCAT(x ORDER BY y) sorts by x, not by y. Only the direction of the first ORDER BY item is used; the expression is ignored.
Reproduced on develop:
constpeople=[{name: 'ann',age: 30},{name: 'bob',age: 20},{name: 'cid',age: 25}];alasql('SELECT VALUE GROUP_CONCAT(name ORDER BY age) FROM ?',[people]);// 'ann,bob,cid' expected 'bob,cid,ann' (MySQL; string_agg in PostgreSQL)
Cause
getGroupConcatParams in src/423groupby.js (added in #2418) passes only col.order[0].direction to the aggregator, which then sorts the collected values themselves.
Direction
Collect each value together with its sort key (all ORDER BY items, evaluated per row), sort by the keys at the end, then join. Ordering by the value itself (GROUP_CONCAT(name ORDER BY name)) stays a special case of this.
This fixes a wrong result nobody can rely on, so it can go into 4.x.
Tests: the example above, DESC, two ORDER BY items, ORDER BY the value itself, and together with SEPARATOR.
Activity
mateuscmtropical commentedon Nov 11, 2026
Hi, I'd like to work on this one.
mateuscmtropical commentedon Nov 11, 2026
Hi, I've opened a PR for this: #2995