Available in versions: Dev (3.22) | Latest (3.21) | 3.20 | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14

CRUD: Merge

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

A MERGE (or UPSERT) operation can be executed on an org.jooq.UpdatableRecord when it is created in the client irrespective of whether the corresponding record already exists in the database. If it does not exist, the operation will have INSERT semantics. If it does exist, it will have UPDATE semantics.

This is different from store() as the decision will be made in the database, not in the client.

// Create a new record
BookRecord book = create.newRecord(BOOK);

// Merge the record: 
// INSERT INTO BOOK (ID, TITLE)
// VALUES (1, '1984')
// ON CONFLICT (ID)
// DO UPDATE SET TITLE = excluded.TITLE
book.steId(1)
book.setTitle("1984");
book.merge();

Some variant of INSERT .. ON DUPLICATE KEY UPDATE will be executed, or its emulation via INSERT .. ON CONFLICT or MERGE.

References to this page

Feedback

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

The jOOQ Logo