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

Optional join paths

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

A key capability when creating dynamic SQL queries is to be able to provide optional table expressions, also by means of explicit path joins.

boolean condition = ...

create.select(BOOK.ID)
      .from(BOOK)
      .join(condition ? BOOK.author() : noPath())
      .fetch();

The above query produces:

-- If condition is true
SELECT book.id FROM book JOIN author ON book.author_id = author.id

-- If condition is false
SELECT book.id FROM book

The noPath() expression will be ignored. If that means the FROM clause is empty, then the entire clause will be omitted. If noPath() is supplied, the optional ON clause has no effect and will be ignored.

The noPath() expression is supported only in the DSL API, not in the model API, where the behaviour of noPath() is undefined.
This API has been added in jOOQ versions 3.21.0, 3.20.9, and 3.19.28.

Feedback

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

The jOOQ Logo