New versions: Dev (3.16) | Latest (3.15)

WHEN clause

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

A trigger can specify a filter, which helps avoid context switching, etc. when the trigger does not need to be fired. This can be achieved with the WHEN clause, which can access the OLD and NEW pseudo table columns, see also the REFERENCING clause.

create.createTrigger("trg")
      .beforeInsert()
      .on(BOOK)
      .referencingNewAs("n")
      .forEachRow()
      .when(BOOK.as("n").TITLE.isNotNull())
      .as(insertInto(LOG).columns(LOG.TEXT).values("Row inserted in BOOK"))
      .execute();

Feedback

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

The jOOQ Logo