r2dbc / r2dbc-mssql

R2DBC Driver for Microsoft SQL Server using TDS (Tabular Data Stream) Protocol
Apache License 2.0
178 stars 32 forks source link

Insert multiple rows as single statement #282

Open sebastian-alfers opened 8 months ago

sebastian-alfers commented 8 months ago

I am trying to insert something like this:

insert into table(id, db_timestamp) values (1, SYSDATETIME()), (2,SYSDATETIME());

Looking at the two rows, they have the same timestamp. When I do the same in code, the timestamps are different:

val insertSql = "insert into table(id, db_timestamp) values(@id, SYSDATETIME())"
connection
     .createStatement(insertSql)
     .bind("@id", 1).add()
     .bind("@id", 2).add()
     .execute()

Is it possible that the code above creates two separate statements, instead of combining them into a single insert with multiples values?

Any idea how to achieve this?