RPayne
RPayne

Reputation: 75

Does the Spanner Client support bulk inserts?

Google's Spanner supports SQL "bulk" Inserts e.g. from doco

INSERT INTO Singers (SingerId, FirstName, LastName) VALUES(1, 'Marc', 'Richards'), (2, 'Catalina', 'Smith'), (3, 'Alice', 'Trentor');

However I cannot find any support for this in the Go Client. The Go Client "Statement" type supports single-row inserts and I have used the BatchUpdate() function to execute a batch of single-row inserts, but I cannot find any support for bulk-inserts.

Does the Spanner Client support bulk inserts ?

Upvotes: 1

Views: 1612

Answers (1)

Knut Olav Løite
Knut Olav Løite

Reputation: 3512

Yes, there are a number of ways that you can do that:

  1. The one mentioned by yourself: Use the BatchUpdate method to execute a collection of individual INSERT statements. An example can be found here.
  2. You can execute an INSERT statement that inserts multiple rows by calling the Update method with a SQL string that inserts multiple rows. An example can be found here.
  3. The most efficient way to insert a bulk of rows is to use mutations instead of DML. Use the Apply method to insert a collection of (insert) mutations. An example can be found here

Upvotes: 2

Related Questions