Skip to content

Commit c2e0552

Browse files
committed
SQL: [Docs] Add limitation for sorting on aggs (#52210)
Add a section to point out that when ordering by an aggregate only plain aggregate functions are allowed, no scalars/operators can be used on top of them. Fixes: #52204 (cherry picked from commit 78a1185)
1 parent a3ebacf commit c2e0552

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

docs/reference/sql/limitations.asciidoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ SELECT * FROM test GROUP BY age ORDER BY COUNT(*) LIMIT 100;
118118
It is possible to run the same queries without a `LIMIT` however in that case if the maximum size (*10000*) is passed,
119119
an exception will be returned as {es-sql} is unable to track (and sort) all the results returned.
120120

121+
Moreover, the aggregation(s) used in the `ORDER BY must be only plain aggregate functions. No scalar
122+
functions or operators can be used, and therefore no complex columns that combine two ore more aggregate
123+
functions can be used for ordering. Here are some examples of queries that are *not allowed*:
124+
125+
[source, sql]
126+
--------------------------------------------------
127+
SELECT age, ROUND(AVG(salary)) AS avg FROM test GROUP BY age ORDER BY avg;
128+
129+
SELECT age, MAX(salary) - MIN(salary) AS diff FROM test GROUP BY age ORDER BY diff;
130+
--------------------------------------------------
131+
121132
[float]
122133
=== Using aggregation functions on top of scalar functions
123134

0 commit comments

Comments
 (0)