# MergeSelectStatement

open class MergeSelectStatement(dest: Table, selectQuery: QueryAlias, val on: Op<Boolean>) : MergeStatement

Represents an SQL MERGE statement. It encapsulates the logic to perform conditional updates, insertions, or deletions.

Here is only the part specific for the Query as a source implementation. Look into MergeStatement to find the base implementation of that command.

#### Parameters

dest

The destination Table where records will be merged into.

## Constructors

MergeSelectStatement
Link copied to clipboard
constructor(dest: Table, selectQuery: QueryAlias, on: Op<Boolean>)

## Properties

isAlwaysBatch
Link copied to clipboard
open val isAlwaysBatch: Boolean

Whether the SQL statement is meant to be performed as part of a batch execution.

on
Link copied to clipboard
val on: Op<Boolean>

The join condition Op that specifies how to match records in both `source` and `dest`.

table
Link copied to clipboard
val table: Table

The destination Table where records will be merged into.

targets
Link copied to clipboard
val targets: List<Table>
type
Link copied to clipboard
val type: StatementType

## Functions

arguments
Link copied to clipboard
open override fun arguments(): Iterable<Iterable<Pair<IColumnType<*>, Any?>>>

Returns all mappings of columns and expression types to their values needed to prepare an SQL statement.

execute
Link copied to clipboard
fun execute(transaction: Transaction): Int?

Executes the SQL statement directly in the provided transaction and returns the generated result, or `null` if either no result was retrieved or if the transaction blocked statement execution.

executeInternal
Link copied to clipboard
open override fun PreparedStatementApi.executeInternal(transaction: Transaction): Int?

Determines the exact way that an SQL statement is executed in a transaction and applies any necessary logic before returning the result generated by the executed statement.

prepared
Link copied to clipboard
open fun prepared(transaction: Transaction, sql: String): PreparedStatementApi

Uses a transaction connection and an sql string representation to return a precompiled SQL statement, stored as an implementation of PreparedStatementApi.

prepareSQL
Link copied to clipboard
open override fun prepareSQL(transaction: Transaction, prepared: Boolean): String

Returns the string representation of an SQL statement.

whenMatchedDelete
Link copied to clipboard
fun whenMatchedDelete(and: Op<Boolean>? = null)

Specifies a delete operation to be executed when a matching record is found in the destination table.

whenMatchedDoNothing
Link copied to clipboard
fun whenMatchedDoNothing(and: Op<Boolean>? = null)

Postgres only. Specifies that no operation should be performed when a matching record is found in the destination table.

whenMatchedUpdate
Link copied to clipboard
fun whenMatchedUpdate(and: Op<Boolean>? = null, deleteWhere: Op<Boolean>? = null, body: (UpdateStatement) -> Unit)

Defines an update operation to be executed when a matching record is found in the destination table.

whenNotMatchedDoNothing
Link copied to clipboard
fun whenNotMatchedDoNothing(and: Op<Boolean>? = null)

Postgres only. Specifies that no operation should be performed when no matching record is found in the destination table.

whenNotMatchedInsert
Link copied to clipboard
fun whenNotMatchedInsert(and: Op<Boolean>? = null, overridingUserValue: Boolean = false, overridingSystemValue: Boolean = false, body: (InsertStatement<Int>) -> Unit)

Defines an insert operation to be performed when there is no matching record in the destination table.