InsertQuery
An INSERT under construction.
Its one real job is the pair of lists that have to match: the columns, and the values in the same order. Declaring a column with value or values puts a @name placeholder in the second list for it, so the two cannot drift, and the values themselves are supplied at the terminal like every other parameter. Where a value is not a parameter but an expression - now(), DEFAULT, a subselect - valueExpression puts that there instead.
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
Switches this query to the result style: every terminal on the returned object hands back a DataResult instead of throwing.
Turns this query into a step of a TransactionPlan instead of something to run now.
Names the target columns for an INSERT … SELECT, where there are no values to declare.
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.
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.
Inserts the rows a SELECT produces instead of a VALUES list.
Configures the ON CONFLICT clause.
Builds the driver query a terminal is about to run, with this query's own converters on it.
Marks the WITH clause RECURSIVE.
Registers a ParameterConverter for this query and nothing else.
Registers a ResultConverter for this query and nothing else.
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 a map's keys, each taking its value from the parameter of the same name.
As valueExpression, for several columns at once.
Adds a common table expression. Call it more than once for more than one.