JOOQ - Update Statement with Expression

Viewed 379

In PostgreSQL you can use an expression which is able to make use of the column values for the given row to define the value in the set statement i.e

UPDATE some_table
SET col_a = (col_b != 1)
WHERE col_c = 'some val'

Is there a way to do this in JOOQ? - I've looked through the JOOQ documentation, but I can't see any reference to it

2 Answers

I'm assuming col_a is a Field<Boolean>, in case of which, you can wrap a Condition in a Field<Boolean> expression using DSL.field(Condition)

// As always, assuming you have this static import:
import static org.jooq.impl.DSL.*;

ctx.update(SOME_TABLE)
   .set(SOME_TABLE.COL_A, field(SOME_TABLE.COL_B.ne(1)))
   .where(SOME_TABLE.COL_C.eq("some val"))
   .execute();
Related