Hi, so I was trying this replace code in PostgreSQ...
# exposed
y
Hi, so I was trying this replace code in PostgreSQL and it seems that the on conflict only takes the primary key unique constraints
Copy code
override fun replace(
    table: Table,
    data: List<Pair<Column<*>, Any?>>,
    transaction: Transaction
): String {
    val builder = QueryBuilder(true)
    val sql = if (data.isEmpty()) {
        ""
    } else {
        data.appendTo(builder, prefix = "VALUES (", postfix = ")") { (col, value) -> registerArgument(col, value) }.toString()
    }

    val columns = data.map { it.first }

    val def = super.insert(false, table, columns, sql, transaction)

    val uniqueCols = table.primaryKey?.columns
    if (uniqueCols.isNullOrEmpty()) {
        transaction.throwUnsupportedException("PostgreSQL replace table must supply at least one primary key.")
    }
    val conflictKey = uniqueCols.joinToString { transaction.identity(it) }
    return def + "ON CONFLICT ($conflictKey) DO UPDATE SET " + columns.joinToString { "${transaction.identity(it)}=EXCLUDED.${transaction.identity(it)}" }
}
is this intentional? why not include all unique indices ? I can try fixing it with a PR if needed 🙂
t
Sure, it's not intentional:) But please add appropriated test
y
👍