Is there any way of executing a batchInsert
in JOOQ getting the results as you would in a regular insertInto().set().returning()
?
E.g:
Having an entity as follows:
data class Person(
val id: Int,
val name: String,
)
When running: (pseudo-code)
DSL.batchInsert(personRecords).returning(PERSON.ID, PERSON.NAME).execute()
I wanna get a result set of the records inserted.
So my goal here is to get the insert result rows of a batch of inserts. I don't mind to use a different approach but I would really prefer to keep them in a batch. FYI: I'm using JOOQ 3.14 with a Postgres DB.
As of jOOQ 3.16, there isn't yet, see this pending feature request: https://github.com/jOOQ/jOOQ/issues/3327
However, you can bulk insert your records instead, and return generated values. Since PostgreSQL doesn't have any sophisticated execution plan cache, the difference between batch and bulk insertions might not be too big...?
Try this:
ctx.insertInto(PERSON)
.valuesOfRecords(personRecords)
.returning(PERSON.ID, PERSON.NAME)
.fetch();