Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11 | 3.10

TRUE and FALSE condition

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

When a conditional expression is mandatory, or when using dynamic SQL, it may be required to provide a "dummy" condition that always evaluates to TRUE or FALSE. For this purpose, you can use DSL.trueCondition() or DSL.falseCondition(). For example:

TRUE

TRUE is the identity value of the AND boolean operator, and can be used for procedural or functional reduction of a set of values to a condition:

TRUE
AND
  ID = 1
AND
  TITLE = 'Animal Farm'
Condition condition = trueCondition();
if (id != null)
    condition = condition.and(BOOK.ID.eq(id));
if (title != null)
    condition = condition.and(BOOK.TITLE.eq(title));

If a dialect does not support boolean column types, jOOQ will simply generate 1 = 1.

FALSE

FALSE is the identity value of the OR boolean operator, and can be used for procedural or functional reduction of a set of values to a condition:

FALSE
OR
  ID = 1
OR
  ID = 7
List<Integer> list = List.of(1, 7);
Condition condition = list
    .stream()
    .map(BOOK.ID::eq)
    .reduce(falseCondition(), Condition::or)

If a dialect does not support boolean column types, jOOQ will simply generate 1 = 0.

References to this page

Feedback

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

The jOOQ Logo