-
Notifications
You must be signed in to change notification settings - Fork 693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ignored for PostgreSQL #290
Comments
The following works. Based around #167 class BatchInsertOrIgnore(table: Table) : BatchInsertStatement(table, false) {
override fun prepareSQL(transaction: Transaction): String {
return "${super.prepareSQL(transaction)} ON CONFLICT DO NOTHING"
}
}
fun <T : Table, E> T.batchInsertOrIgnore(data: List<E>, body: BatchInsertOrIgnore.(E) -> Unit): List<Int> {
return data.takeIf { it.isNotEmpty() }?.let {
val insert = BatchInsertOrIgnore(this)
data.forEach {
insert.addBatch()
body(insert, it)
}
TransactionManager.current().exec(insert)
columns.firstOrNull { it.columnType.isAutoInc }?.let { idCol ->
insert.generatedKey?.mapNotNull {
val value = it[idCol]
when (value) {
is Long -> value.toInt()
is Int -> value
null -> null
else -> error("can't find primary key of type Int or Long; map['$idCol']='$value' (where map='$it')")
}
}
}
}.orEmpty()
} |
Hey @AllanWang @Tapac I am trying to use this functionality in batchInsert for postgres aka |
Hi @Rubyj The tests I'm running using PostgreSQL with Could you please confirm if this issue persists on your end with current version 0.44.0? If it does, please consider opening a new issue on YouTrack, so that we can attempt to investigate further. |
As of now, I don't believe it is added in the
VendorDialect
subclass. I am still doing my research on this, but here is what I've noticed:ON CONFLICT DO NOTHING
.ON CONFLICT (id) DO UPDATE SET ...;
Where id must be specified (could be primary key by default?) and set must be specified. For set, you can map the column names to "${name} = EXCLUDED.${name}", which will set everything to the new valueThe text was updated successfully, but these errors were encountered: