Available in versions: Dev (3.20) | Latest (3.19) | 3.18

GROUP BY column index

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

To work against some of SQL's verbosity, some SQL dialects support grouping by column index (starting from 1):

It is not recommended to use this feature in jOOQ as indexes tend to shift without developers noticing. The feature is supported mainly so jOOQ's SQL parser can parse and translate it. If you want to avoid redundancy in jOOQ, better resort to using a dynamic SQL style.

Dialect support

This example using jOOQ:

select(BOOK.AUTHOR_ID, count()).from(BOOK).groupBy(inline(1))

Translates to the following dialect specific expressions:

ASE, Access, BigQuery, DB2, Derby, Exasol, H2, HSQLDB, Hana, Oracle, SQLDataWarehouse, SQLServer, Sybase

SELECT
  BOOK.AUTHOR_ID,
  count(*)
FROM BOOK
GROUP BY BOOK.AUTHOR_ID

Aurora MySQL, Aurora Postgres, CockroachDB, DuckDB, Firebird, Informix, MariaDB, MemSQL, MySQL, Postgres, Redshift, SQLite, Snowflake, Teradata, Trino, Vertica, YugabyteDB

SELECT
  BOOK.AUTHOR_ID,
  count(*)
FROM BOOK
GROUP BY 1

(These are currently generated with jOOQ 3.20, see #10141), or translate your own on our website

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo