Available in versions: Dev (3.18) | Latest (3.17)

Tables as SelectField

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

An org.jooq.Table expression extends the org.jooq.SelectField type, and as such, can be used in the SELECT clause directly, as well as everywhere else a SelectField is accepted, e.g. in nested records. This is specifically useful for (generated) table references. The following shows how to project a nested org.jooq.TableRecord:

Result<Record2<AuthorRecord, BookRecord>> result =
create.select(AUTHOR, BOOK)
      .from(AUTHOR)
      .join(BOOK).on(AUTHOR.ID.eq(BOOK.AUTHOR_ID))
      .fetch();

This plays very well together with implicit joins:

Result<Record2<AuthorRecord, BookRecord>> result =
create.select(BOOK.author(), BOOK)
      .from(BOOK)
      .fetch();

Behind the scenes, the implementation may either be native in dialects that support this kind of projection (e.g. PostgreSQL), or emulated using the usual nested records emulations.

Feedback

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

The jOOQ Logo