Optional conditional expressions
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
boolean condition = ... create.select(BOOK.ID) .from(BOOK) .where(condition ? BOOK.ID.eq(10) : noCondition()) .fetch();
The above query produces:
-- If condition is true SELECT book.id FROM book WHERE book.id = 10 -- If condition is false SELECT book.id FROM book
noCondition() expression will be ignored. If that means the clause is empty, then the entire clause will be omitted. This does not apply to clauses that project a
Record type, including the SELECT clause, row value expressions, as well as function calls, in case of which a
NULL value will be projected.
Some additional interactions of the
noCondition() can be seen in the section about TRUE and FALSE conditions.