是否可以使用jOOQ的batchAll()加载器在发现重复项时仅更新某些字段?与onDublicateKeyUpdate()用于单个记录的方式类似:https://www.jooq.org/doc/latest/manual/sql-building/sql-statements/insert-statement/insert-on-duplicate-key/。
我想要更改的代码是,当有重复的字段时只更新一个字段:
dsl.loadInto(TABLE)
.batchAll()
.onDuplicateKeyUpdate()
.loadRecords(records)
.fields(TABLE.fields())
.execute();发布于 2021-04-22 16:06:01
不,这在Loader API中是不可能的,但您可以通过编程方式使用batch API或甚至使用batched connection对单个语句进行普通批处理,后者收集所有JDBC语句并延迟执行,直到可以执行批处理:
dsl.batched(c -> {
for (Record record : records) {
c.dsl().insertInto(TABLE)
.set(record)
.onDuplicateKeyUpdate()
.set(TABLE.FIELD_OF_INTEREST, record.get(TABLE.FIELD_OF_INTEREST))
.execute(); // Actual execution is delayed until the end of the lambda
}
}); // Now, all collected statements are batched togetherhttps://stackoverflow.com/questions/67184438
复制相似问题