November 2019
Beginner to intermediate
470 pages
11h 59m
English
Grouping sets are very useful if we want to run more than one aggregate at the same time. Using grouping sets can speed up aggregation because we don't have to process the data more than once.
Here is an example of this:
test=# SELECT x % 2, array_agg(x) FROM generate_series(1, 4) AS x GROUP BY ROLLUP (1); ?column? | array_agg ----------+----------- 0 | {2,4} 1 | {1,3} | {2,4,1,3} (3 rows)
PostgreSQL offers more than just the ROLLUP clause. The CUBE and GROUPING SETS clauses are also supported.
Read now
Unlock full access