Browse Source

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
Marios Trivyzas 5 years ago
parent
commit
78a1185549
1 changed files with 11 additions and 0 deletions
  1. 11 0
      docs/reference/sql/limitations.asciidoc

+ 11 - 0
docs/reference/sql/limitations.asciidoc

@@ -118,6 +118,17 @@ SELECT * FROM test GROUP BY age ORDER BY COUNT(*) LIMIT 100;
 It is possible to run the same queries without a `LIMIT` however in that case if the maximum size (*10000*) is passed,
 an exception will be returned as {es-sql} is unable to track (and sort) all the results returned.
 
+Moreover, the aggregation(s) used in the `ORDER BY must be only plain aggregate functions. No scalar
+functions or operators can be used, and therefore no complex columns that combine two ore more aggregate
+functions can be used for ordering. Here are some examples of queries that are *not allowed*:
+
+[source, sql]
+--------------------------------------------------
+SELECT age, ROUND(AVG(salary)) AS avg FROM test GROUP BY age ORDER BY avg;
+
+SELECT age, MAX(salary) - MIN(salary) AS diff FROM test GROUP BY age ORDER BY diff;
+--------------------------------------------------
+
 [float]
 === Using aggregation functions on top of scalar functions