This repository was archived by the owner on Mar 13, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed
google/cloud/sqlalchemy_spanner Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -807,6 +807,7 @@ class SpannerDialect(DefaultDialect):
807807 insert_returning = True
808808 update_returning = True
809809 delete_returning = True
810+ supports_multivalues_insert = True
810811
811812 ddl_compiler = SpannerDDLCompiler
812813 preparer = SpannerIdentifierPreparer
Original file line number Diff line number Diff line change @@ -209,3 +209,32 @@ class SchemaUser(Base):
209209 select (SchemaUser ).where (SchemaUser .name == "NewName" )
210210 ).all ()
211211 eq_ (0 , len (users ))
212+
213+ def test_multi_row_insert (self , connection ):
214+ """Ensures we can perform multi-row inserts."""
215+
216+ class Base (DeclarativeBase ):
217+ pass
218+
219+ class User (Base ):
220+ __tablename__ = "users"
221+ ID : Mapped [int ] = mapped_column (primary_key = True )
222+ name : Mapped [str ] = mapped_column (String (20 ))
223+
224+ with connection .engine .begin () as conn :
225+ inserted_rows = list (
226+ conn .execute (
227+ User .__table__ .insert ()
228+ .values ([{"name" : "a" }, {"name" : "b" }])
229+ .returning (User .__table__ .c .ID , User .__table__ .c .name )
230+ )
231+ )
232+
233+ eq_ (2 , len (inserted_rows ))
234+ eq_ ({"a" , "b" }, {row .name for row in inserted_rows })
235+
236+ with connection .engine .connect () as conn :
237+ selected_rows = list (conn .execute (User .__table__ .select ()))
238+
239+ eq_ (len (inserted_rows ), len (selected_rows ))
240+ eq_ (set (inserted_rows ), set (selected_rows ))
You can’t perform that action at this time.
0 commit comments