Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JOOQ dynamic multiple values insert

I have a list of records and I need to insert it in one query with upsert like

INSERT INTO table1 (name, lastname) 
VALUES ('name1', 'lastname1'), ('name2', 'lastname2') 
    ON CONFLICT DO NOTHING;

Not batch or merge and necessary with 'on conflict' logic

like image 238
E.Big Avatar asked Sep 13 '25 05:09

E.Big


1 Answers

Use the new jOOQ 3.15 InsertValuesStep2.valuesOfRows():

insertInto(table1, table1.name, table1.lastname)
    .valuesOfRows(usersForInsert.map { DSL.row(it.name, it.lastname) })
    .onConflictDoNothing()
    .execute()
like image 90
Lukas Eder Avatar answered Sep 14 '25 22:09

Lukas Eder