4

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

2 Answers 2

4

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() 
Sign up to request clarification or add additional context in comments.

Comments

-1

Made it so clean with such approach in Kotlin :

insertInto(table1, table1.name, table1.lastname) .apply { usersForInsert.forEach { user -> values(user.name, user.lastname) } } .onConflictDoNothing() .execute() 

Thanks

1 Comment

This will not work without calling at least on values call outside the apply because execute() can only be called on the InsertValuesStepN<> generic.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.