Search code examples
springr2dbc

How to execute multiple inserts in batch in r2dbc?


I need to insert multiple rows into one table in one batch. In DatabaseClient i found insert() statement and using(Publisher objectToInsert) method which has multiple objects as argument. But would it insert them in one batch or not? Another possible solution is connection.createBatch(), but it has a drowback : I cannot pass my Entity object there and i cannot generate sql query from the entity.

So, is it possible to create batch insert in r2dbc?


Solution

  • There are two questions:

    Would DatabaseClient.insert() insert them in one batch or not?

    Not a batch.

    Is it possible to create batch insert in r2dbc? (except Connection.createBatch())

    No, use Connection.createBatch() is only one way to create a Batch for now.

    See also issues: