Skip to content

Commit 5c4cb0e

Browse files
committed
Document GROUP BY AUTO syntax
1 parent 2b6a59e commit 5c4cb0e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/src/main/sphinx/sql/select.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,32 @@ Complex grouping operations are often equivalent to a `UNION ALL` of simple
379379
does not apply, however, when the source of data for the aggregation
380380
is non-deterministic.
381381

382+
### AUTO
383+
384+
When `AUTO` is specified, the Trino engine automatically determines the grouping
385+
columns instead of requiring them to be listed explicitly. In this mode, any
386+
column in the `SELECT` list that is not part of an aggregate function is
387+
implicitly treated as a grouping column.
388+
389+
This example query calculates the total account balance per market segment.
390+
The `AUTO` clause derives `mktsegment` as the grouping key, since it is not used
391+
in any aggregate function (i.e., `sum`).
392+
393+
```sql
394+
SELECT mktsegment, sum(acctbal) FROM shipping GROUP BY AUTO;
395+
```
396+
397+
```text
398+
mktsegment | _col1
399+
------------+--------------------
400+
BUILDING | 1444587.8
401+
MACHINERY | 1296958.61
402+
HOUSEHOLD | 1279340.66
403+
FURNITURE | 1265282.8
404+
AUTOMOBILE | 1395695.7200000004
405+
(5 rows)
406+
```
407+
382408
### GROUPING SETS
383409

384410
Grouping sets allow users to specify multiple lists of columns to group on.

0 commit comments

Comments
 (0)