Wilson Chuks
08/16/2025, 1:45 PMbatchUpsert shouldReturnGeneratedValues: Boolean = true, doc:
Does it mean the updated rows won't be returned?
/**
* Represents the SQL statement that either batch inserts new rows into a table, or updates the existing rows if insertions violate unique constraints.
*
* @param data Collection of values to use in batch upsert.
* @param keys (optional) Columns to include in the condition that determines a unique constraint match. If no columns are provided,
* primary keys will be used. If the table does not have any primary keys, the first unique index will be attempted.
* @param onUpdate Lambda block with an [UpdateStatement] as its argument, allowing values to be assigned to the UPDATE clause.
* To specify manually that the insert value should be used when updating a column, for example within an expression
* or function, invoke `insertValue()` with the desired column as the function argument.
* If left null, all columns will be updated with the values provided for the insert.
* @param onUpdateExclude List of specific columns to exclude from updating.
* If left null, all columns will be updated with the values provided for the insert.
* @param where Condition that determines which rows to update, if a unique violation is found.
* @param shouldReturnGeneratedValues Specifies whether newly generated values (for example, auto-incremented IDs) should be returned.
* See [Batch Insert](<https://github.com/JetBrains/Exposed/wiki/DSL#batch-insert>) for more details.
* @sample org.jetbrains.exposed.sql.tests.shared.dml.UpsertTests.testBatchUpsertWithNoConflict
*/
fun <T : Table, E : Any> T.batchUpsert(
data: Iterable<E>,
vararg keys: Column<*>,
onUpdate: (UpsertBuilder.(UpdateStatement) -> Unit)? = null,
onUpdateExclude: List<Column<*>>? = null,
where: (SqlExpressionBuilder.() -> Op<Boolean>)? = null,
shouldReturnGeneratedValues: Boolean = true,
body: BatchUpsertStatement.(E) -> Unit
): List<ResultRow> {
return batchUpsert(data.iterator(), null, onUpdate, onUpdateExclude, where, shouldReturnGeneratedValues, keys = keys, body = body)
}