From 2bcc97da424eef7db9a5d02f81d02344925415ee Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 18 Jul 2022 15:08:37 -0400 Subject: implement batched INSERT..VALUES () () for executemany the feature is enabled for all built in backends when RETURNING is used, except for Oracle that doesn't need it, and on psycopg2 and mssql+pyodbc it is used for all INSERT statements, not just those that use RETURNING. third party dialects would need to opt in to the new feature by setting use_insertmanyvalues to True. Also adds dialect-level guards against using returning with executemany where we dont have an implementation to suit it. execute single w/ returning still defers to the server without us checking. Fixes: #6047 Fixes: #7907 Change-Id: I3936d3c00003f02e322f2e43fb949d0e6e568304 --- doc/build/tutorial/orm_data_manipulation.rst | 7 +++---- doc/build/tutorial/orm_related_objects.rst | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'doc/build/tutorial') diff --git a/doc/build/tutorial/orm_data_manipulation.rst b/doc/build/tutorial/orm_data_manipulation.rst index b0b67f53c..f6237f4aa 100644 --- a/doc/build/tutorial/orm_data_manipulation.rst +++ b/doc/build/tutorial/orm_data_manipulation.rst @@ -122,10 +122,9 @@ method: >>> session.flush() {opensql}BEGIN (implicit) - INSERT INTO user_account (name, fullname) VALUES (?, ?) - [...] ('squidward', 'Squidward Tentacles') - INSERT INTO user_account (name, fullname) VALUES (?, ?) - [...] ('ehkrabs', 'Eugene H. Krabs') + INSERT INTO user_account (name, fullname) VALUES (?, ?), (?, ?) RETURNING id + [...] ('squidward', 'Squidward Tentacles', 'ehkrabs', 'Eugene H. Krabs') + Above we observe the :class:`_orm.Session` was first called upon to emit SQL, so it created a new transaction and emitted the appropriate INSERT statements diff --git a/doc/build/tutorial/orm_related_objects.rst b/doc/build/tutorial/orm_related_objects.rst index 0df611e45..a6bb2b9a3 100644 --- a/doc/build/tutorial/orm_related_objects.rst +++ b/doc/build/tutorial/orm_related_objects.rst @@ -198,12 +198,11 @@ newly generated primary key of the ``user_account`` row is applied to the >>> session.commit() {opensql}INSERT INTO user_account (name, fullname) VALUES (?, ?) [...] ('pkrabs', 'Pearl Krabs') - INSERT INTO address (email_address, user_id) VALUES (?, ?) - [...] ('pearl.krabs@gmail.com', 6) - INSERT INTO address (email_address, user_id) VALUES (?, ?) - [...] ('pearl@aol.com', 6) + INSERT INTO address (email_address, user_id) VALUES (?, ?), (?, ?) RETURNING id + [...] ('pearl.krabs@gmail.com', 6, 'pearl@aol.com', 6) COMMIT + .. _tutorial_loading_relationships: Loading Relationships -- cgit v1.2.1