spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

'upsert' syntax and real 'batch' syntax support

Open arenick001 opened this issue 4 months ago • 2 comments

Now when I want to insert multiple records at once, I must use the saveAll method. And the saveAll method uses the save method↓

// in class `SimpleR2dbcRepository`
public <S extends T> Mono<S> save(S objectToSave) {

	Assert.notNull(objectToSave, "Object to save must not be null");

	if (this.entity.isNew(objectToSave)) {
		return this.entityOperations.insert(objectToSave);
	}

	return this.entityOperations.update(objectToSave);
}

it wiil check if each record is new. I'd like to know if there is any support for 'upsert' syntax or real batch insert syntax (insert into ... values ​​(...), (...);) Thanks in advance :)

arenick001 avatar Sep 09 '25 07:09 arenick001

Furthermore, I forked the repository and wrote some code to implement the above functionality. If it is allowed, I think I can submit a PR when I complete it.

arenick001 avatar Sep 09 '25 07:09 arenick001

There are already issues related to upserts focused on Spring Data JDBC, since they are from before the two projects were merged:

#493 describes pretty much the request here but for Spring Data JDBC #450 describes the use of upsert syntax when updating referenced entities in Spring Data JDBC (does not apply for R2DBC)

schauder avatar Sep 11 '25 11:09 schauder