InsertQuery
An INSERT under construction. value and values declare a column together with its @name placeholder in VALUES, so the two lists cannot drift; valueExpression puts SQL there instead - now(), DEFAULT, a subselect. The values are supplied at the terminal.
val id = db.insertInto("citizens")
.values(listOf("cognomen", "tribe"))
.valueExpression("enrolled_at", "now()")
.onConflict {
onColumns("cognomen")
doUpdate("tribe = excluded.tribe")
}
.returning("id")
.fetchFieldStrict<Int>("cognomen" to "Marcus", "tribe" to "Cornelia")Properties
Functions
This query with terminals that return a DataResult instead of throwing, on the boundary dbResult applies - a fetch*Strict that found no row still throws.
Turns this query into a step of a TransactionPlan instead of running it. The parameters given at the step's terminal may hold TransactionValues pointing at earlier steps.
The target columns of an INSERT … SELECT, for fromSelect; the VALUES form declares its own.
Returns an independent copy, so that variants can be built from a shared base.
Carries registered converters into a builder's copy(), alongside whatever clauses it copies.
Runs the statement and returns how many rows it affected.
As fetchField, but the query must return exactly one row rather than at most one.
Runs the query and returns its single row, throwing where the count was anything but one.
Runs the query and hands the first column of each row, as T, to block as forEachRow does.
Runs the query and hands each row, mapped onto T, to block as it arrives, as forEachRow does.
Configures the ON CONFLICT clause.
Adds OVERRIDING SYSTEM VALUE or OVERRIDING USER VALUE, to the VALUES form and to fromSelect alike. null leaves it out.
The driver query every terminal runs, carrying this query's own converters.
Marks the WITH clause RECURSIVE.
Registers a ParameterConverter for this query alone, on the terms of registerResultConverter.
Registers a ResultConverter for this query alone, consulted ahead of the session's. A later registration here wins over an earlier one.
Adds a RETURNING clause, which turns this into a query the fetch* family can read.
Declares one column, taking its value from the @column parameter.
Declares one column taking a SQL expression rather than a parameter - now(), DEFAULT, a subselect.
Declares columns, each taking its value from the parameter of the same name.
Declares columns from data's keys, each taking its value from the parameter of the same name. The map's values are not read, so pass it to the terminal too: insertInto("t").values(row).executeUpdate(row).
As valueExpression, for several columns at once.
Adds a common table expression. Call it more than once for more than one.