# upsertReturning

fun <T : Table> T.upsertReturning(vararg keys: Column<*>, returning: List<Expression<*>> = columns, onUpdate: UpsertBuilder.(UpdateStatement) -> Unit? = null, onUpdateExclude: List<Column<*>>? = null, where: SqlExpressionBuilder.() -> Op<Boolean>? = null, body: T.(UpsertStatement<Long>) -> Unit): ReturningStatement

Represents the SQL statement that either inserts a new row into a table, or updates the existing row if insertion would violate a unique constraint, and also returns specified data from the modified rows.

#### Return

A ReturningStatement that will be executed once iterated over, providing ResultRows containing the specified expressions mapped to their resulting data.

#### Parameters

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.

returning

Columns and expressions to include in the returned data. This defaults to all columns in the table.

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.

#### Samples

org.jetbrains.exposed.sql.tests.shared.dml.ReturningTests.testUpsertReturning

fun <T : Table> T.upsertReturning(vararg keys: Column<*>, returning: List<Expression<*>> = columns, onUpdate: List<Pair<Column<*>, Expression<*>>>, onUpdateExclude: List<Column<*>>? = null, where: SqlExpressionBuilder.() -> Op<Boolean>? = null, body: T.(UpsertStatement<Long>) -> Unit): ReturningStatement

### Deprecated

This `upsertReturning()` with `onUpdate` parameter that accepts a List will be removed in future releases. Please use `upsertReturning()` with `onUpdate` parameter that takes an `UpdateStatement` lambda block instead.