From 1b93208b49aa79ebebce1fdcf8898fb85b6718c5 Mon Sep 17 00:00:00 2001 From: Yuval Dinari <> Date: Wed, 24 Jul 2019 11:43:01 +0300 Subject: [PATCH] Take psycopg2.execute_values() page_size parameter value from a flag instead of having it hardcoded in PGCompiler_psycopg2 Fixes: #4623 --- lib/sqlalchemy/dialects/postgresql/psycopg2.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index 3d35e1ba0b..9d9f4d8705 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -77,6 +77,11 @@ psycopg2-specific keyword arguments which are accepted by :ref:`psycopg2_batch_mode` +* ``page_size``: When ``execution_mode`` is ``'values_batch'``, this flag + determines the maximum number of rows to insert in a single request to the database. + If there are more rows than that, they will be sent in several requests (each + containing a single query). Default value is 10000. + * ``use_batch_mode``: This flag allows using psycopg2 faster methods for executing queries with multiple parameters (usually INSERT queries). If equals True or 'execute_batch', ``psycopg2.extras.execute_batch`` is used. @@ -591,7 +596,7 @@ class PGCompiler_psycopg2(PGCompiler): self.dialect = dialect self.multiple_rows = inline self.execute_values_insert_template = None - self.execute_values_page_size = 10000 + super( PGCompiler_psycopg2, PGCompiler_psycopg2).__init__( @@ -687,6 +692,7 @@ class PGDialect_psycopg2(PGDialect): use_native_hstore=True, use_native_uuid=True, execution_mode=None, + page_size=10000, use_batch_mode=False, **kwargs ): @@ -700,6 +706,7 @@ class PGDialect_psycopg2(PGDialect): self.psycopg2_execution_mode = \ EnumPsycopg2ExecutionMode(execution_mode) if execution_mode else \ None + self.psycopg2_page_size = page_size self.psycopg2_batch_mode = use_batch_mode # use_batch_mode supported for backward compatibility. To avoid having to check two flags, @@ -865,7 +872,7 @@ class PGDialect_psycopg2(PGDialect): statement, parameters, template=context.compiled.execute_values_insert_template, - page_size=context.compiled.execute_values_page_size) + page_size=self.psycopg2_page_size) else: # VALUES_BATCH of non-insert query, or STATEMENTS_BATCH self._psycopg2_extras().execute_batch(cursor, statement, parameters) -- 2.47.3