# replace

inline fun <T : Table> T.replace(crossinline body: T.(UpdateBuilder<*>) -> Unit): ReplaceStatement<Long>

Represents the SQL statement that either inserts a new row into a table, or, if insertion would violate a unique constraint, first deletes the existing row before inserting a new row.

Note: This operation is not supported by all vendors, please check the documentation.

#### Samples

org.jetbrains.exposed.sql.tests.shared.dml.ReplaceTests.testReplaceWithExpression

fun <T : Table> T.replace(selectQuery: AbstractQuery<*>, columns: List<Column<*>> = this.columns.filter { it.isValidIfAutoIncrement() }): Int?

Represents the SQL statement that uses data retrieved from a selectQuery to either insert a new row into a table, or, if insertion would violate a unique constraint, first delete the existing row before inserting a new row.

Note: This operation is not supported by all vendors, please check the documentation.

#### Return

The number of inserted (and possibly deleted) rows, or `null` if nothing was retrieved after statement execution.

#### Parameters

selectQuery

Source `SELECT` query that provides the values to insert.

columns

Columns to either insert values into or delete values from then insert into. This defaults to all columns in the table that are not auto-increment columns without a valid sequence to generate new values.

#### Samples

org.jetbrains.exposed.sql.tests.shared.dml.ReplaceTests.testReplaceSelect