docs/api/exposed-r2dbc/org.jetbrains.exposed.v1.r2dbc/batch-upsert.html
suspend fun <T : Table, E : Any> T.batchUpsert(data: Iterable<E>, vararg keys: Column<*>, onUpdate: UpsertBuilder.(UpdateStatement) -> Unit? = null, onUpdateExclude: List<Column<*>>? = null, where: () -> Op<Boolean>? = null, shouldReturnGeneratedValues: Boolean = true, body: BatchUpsertStatement.(E) -> Unit): List<ResultRow>
Represents the SQL statement that either batch inserts new rows into a table, or updates the existing rows if insertions violate unique constraints.
Note: It is a known limitation that R2DBC drivers for H2 and MariaDB do not return a means to access both the generated values and the updated row count from a single statement execution. If the database-accurate updated row count is required, via BatchUpsertStatement.insertedCount, then shouldReturnGeneratedValues should be set to false.
data
Collection of values to use in batch upsert.
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.
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.
onUpdateExclude
List of specific columns to exclude from updating. If left null, all columns will be updated with the values provided for the insert.
where
Condition that determines which rows to update, if a unique violation is found.
shouldReturnGeneratedValues
Specifies whether newly generated values (for example, auto-incremented IDs) should be returned. See Batch Insert for more details.
org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.UpsertTests.testBatchUpsertWithNoConflict
suspend fun <T : Table, E : Any> T.batchUpsert(data: Sequence<E>, vararg keys: Column<*>, onUpdate: UpsertBuilder.(UpdateStatement) -> Unit? = null, onUpdateExclude: List<Column<*>>? = null, where: () -> Op<Boolean>? = null, shouldReturnGeneratedValues: Boolean = true, body: BatchUpsertStatement.(E) -> Unit): List<ResultRow>
Represents the SQL statement that either batch inserts new rows into a table, or updates the existing rows if insertions violate unique constraints.
Note: It is a known limitation that R2DBC drivers for H2 and MariaDB do not return a means to access both the generated values and the updated row count from a single statement execution. If the database-accurate updated row count is required, via BatchUpsertStatement.insertedCount, then shouldReturnGeneratedValues should be set to false.
data
Sequence of values to use in batch upsert.
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.
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.
onUpdateExclude
List of specific columns to exclude from updating. If left null, all columns will be updated with the values provided for the insert.
where
Condition that determines which rows to update, if a unique violation is found.
shouldReturnGeneratedValues
Specifies whether newly generated values (for example, auto-incremented IDs) should be returned. See Batch Insert for more details.
org.jetbrains.exposed.v1.r2dbc.sql.tests.shared.dml.UpsertTests.testBatchUpsertWithSequence
Generated by Dokka © 2026 Copyright