Available in versions: Dev (3.18) | Latest (3.17) | 3.16 | 3.15 | 3.14

Kotlin BOOLEAN value expressions

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

A BOOLEAN column (Field<Boolean>) and a conditional expression (Condition) are not really too different, especially when the dialect supports standard SQL BOOLEAN types.

In jOOQ, the two things can often be used exchangeably, but there are some exceptions, mainly when BOOLEAN operators should be used with (Field<Boolean>):

condition(BOOLEAN_COLUMN1).and(BOOLEAN_COLUMN2)

At least the left side of the expression has to be wrapped with DSL.condition(Field), which is cumbersome.

Using the kotlin extensions module, these operators are also made available on Field<Boolean> directly:

package org.jooq.kotlin

fun Field<Boolean>.and(other: Condition): Condition = condition(this).and(other)
fun Field<Boolean>.or(other: Condition): Condition = condition(this).or(other)
fun Field<Boolean>.not(): Condition = condition(this).not()

// [... and more]

This allows for the leaner version below:

BOOLEAN_COLUMN1.and(BOOLEAN_COLUMN2)

Feedback

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

The jOOQ Logo