bulkInsertOrUpdateReturning
Bulk insert records to the table, determining if there is a key conflict while inserting each of them, automatically performs updates if any conflict exists, and finally returns the specific column.
Usage:
database.bulkInsertOrUpdateReturning(Employees, Employees.id) {
item {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
item {
set(it.id, 5)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
onConflict {
set(it.salary, it.salary + 900)
}
}Generated SQL:
insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)
on conflict (id) do update set salary = t_employee.salary + ?
returning idBy default, the column used in the on conflict statement is the primary key you already defined in the schema definition. If you want, you can specify one or more columns for the on conflict statement as belows:
database.bulkInsertOrUpdateReturning(Employees, Employees.id) {
item {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
item {
set(it.id, 5)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
onConflict(it.name, it.job) {
set(it.salary, it.salary + 900)
}
}Generated SQL:
insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)
on conflict (name, job) do update set salary = t_employee.salary + ?
returning idSince
3.6.0
Return
the returning column's values.
Parameters
the table to be inserted.
the column to return
the DSL block used to construct the expression.
Bulk insert records to the table, determining if there is a key conflict while inserting each of them, automatically performs updates if any conflict exists, and finally returns the specific columns.
Usage:
database.bulkInsertOrUpdateReturning(Employees, Pair(Employees.id, Employees.job)) {
item {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
item {
set(it.id, 5)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
onConflict {
set(it.salary, it.salary + 900)
}
}Generated SQL:
insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)
on conflict (id) do update set salary = t_employee.salary + ?
returning id, jobBy default, the column used in the on conflict statement is the primary key you already defined in the schema definition. If you want, you can specify one or more columns for the on conflict statement as belows:
database.bulkInsertOrUpdateReturning(Employees, Pair(Employees.id, Employees.job)) {
item {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
item {
set(it.id, 5)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
onConflict(it.name, it.job) {
set(it.salary, it.salary + 900)
}
}Generated SQL:
insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)
on conflict (name, job) do update set salary = t_employee.salary + ?
returning id, jobSince
3.6.0
Return
the returning columns' values.
Parameters
the table to be inserted.
the columns to return
the DSL block used to construct the expression.
Bulk insert records to the table, determining if there is a key conflict while inserting each of them, automatically performs updates if any conflict exists, and finally returns the specific columns.
Usage:
database.bulkInsertOrUpdateReturning(Employees, Triple(Employees.id, Employees.job, Employees.salary)) {
item {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
item {
set(it.id, 5)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
onConflict {
set(it.salary, it.salary + 900)
}
}Generated SQL:
insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)
on conflict (id) do update set salary = t_employee.salary + ?
returning id, job, salaryBy default, the column used in the on conflict statement is the primary key you already defined in the schema definition. If you want, you can specify one or more columns for the on conflict statement as belows:
database.bulkInsertOrUpdateReturning(Employees, Triple(Employees.id, Employees.job, Employees.salary)) {
item {
set(it.id, 1)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
item {
set(it.id, 5)
set(it.name, "vince")
set(it.job, "engineer")
set(it.salary, 1000)
set(it.hireDate, LocalDate.now())
set(it.departmentId, 1)
}
onConflict(it.name, it.job) {
set(it.salary, it.salary + 900)
}
}Generated SQL:
insert into t_employee (id, name, job, salary, hire_date, department_id)
values (?, ?, ?, ?, ?, ?), (?, ?, ?, ?, ?, ?)
on conflict (name, job) do update set salary = t_employee.salary + ?
returning id, job, salarySince
3.6.0
Return
the returning columns' values.
Parameters
the table to be inserted.
the columns to return
the DSL block used to construct the expression.