diff options
| author | tsauerwein <tobias.sauerwein@camptocamp.com> | 2016-04-11 23:16:17 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-06-06 16:22:11 -0400 |
| commit | 528509e1bc41c7fe4e51f7bb550db6343b29e841 (patch) | |
| tree | 61fc75fa4357c8ca1b2e4923acfca1fdb79c30eb /test/orm | |
| parent | 2860ae6c4927dbbca9316c81ce15cbbb7df49750 (diff) | |
| download | sqlalchemy-528509e1bc41c7fe4e51f7bb550db6343b29e841.tar.gz | |
Add "render_nulls" flag to bulk_insert as optional performance optimization
Currently, ``Session.bulk_insert_mappings`` omits NULL values which
causes it to break up batches of inserts based on which batches
contain NULL and which do not.
By adding this flag, the same columns are rendered in the INSERT
for all rows allowing them to be batched. The downside is that
server-side defaults are omitted.
Doctext-author: Mike Bayer <mike_mp@zzzcomputing.com>
Change-Id: Iec5969304d4bdbf57290b200331bde02254aa3a5
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/243
Diffstat (limited to 'test/orm')
| -rw-r--r-- | test/orm/test_bulk.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/test/orm/test_bulk.py b/test/orm/test_bulk.py index 878560cf6..0a51a5ad3 100644 --- a/test/orm/test_bulk.py +++ b/test/orm/test_bulk.py @@ -17,11 +17,12 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): @classmethod def setup_mappers(cls): - User, Address = cls.classes("User", "Address") - u, a = cls.tables("users", "addresses") + User, Address, Order = cls.classes("User", "Address", "Order") + u, a, o = cls.tables("users", "addresses", "orders") mapper(User, u) mapper(Address, a) + mapper(Order, o) def test_bulk_save_return_defaults(self): User, = self.classes("User",) @@ -155,6 +156,28 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): ) ) + def test_bulk_insert_render_nulls(self): + Order, = self.classes("Order",) + + s = Session() + with self.sql_execution_asserter() as asserter: + s.bulk_insert_mappings( + Order, + [{'id': 1, 'description': 'u1new'}, + {'id': 2, 'description': None}, + {'id': 3, 'description': 'u3new'}], + render_nulls=True + ) + + asserter.assert_( + CompiledSQL( + "INSERT INTO orders (id, description) VALUES (:id, :description)", + [{'id': 1, 'description': 'u1new'}, + {'id': 2, 'description': None}, + {'id': 3, 'description': 'u3new'}] + ) + ) + class BulkUDPostfetchTest(BulkTest, fixtures.MappedTest): @classmethod |
