Grouping by large number of columns with ordinal reference

Viewed 149

I have a lengthy query in postgres that requires grouping by 30 different columns referenced in the query

At the moment, I have manually listed the group by columns by their ordinal value in the query

SELECT ...
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30

Does a better way of doing this exist? I have tried

SELECT...
GROUP BY array(generate_series(1, 30))

But this method fails. Is there a way to use generate_series in the GROUP BY clause to reference columns in the query in cases where queries require a large number of group by columns?

0 Answers
Related