summaryrefslogtreecommitdiff
path: root/doc/src/extras.rst
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/extras.rst')
-rw-r--r--doc/src/extras.rst57
1 files changed, 57 insertions, 0 deletions
diff --git a/doc/src/extras.rst b/doc/src/extras.rst
index d33b8ee..5ef4223 100644
--- a/doc/src/extras.rst
+++ b/doc/src/extras.rst
@@ -974,6 +974,63 @@ converted into lists of strings.
future versions.
+
+.. _fast-exec:
+
+Fast execution helpers
+----------------------
+
+The current implementation of `~cursor.executemany()` is (using an extremely
+charitable understatement) not particularly performing. These functions can
+be used to speed up the repeated execution of a statement againts a set of
+parameters. By reducing the number of server roundtrips the performance can be
+`orders of magnitude better`__ than using `!executemany()`.
+
+.. __: https://github.com/psycopg/psycopg2/issues/491#issuecomment-276551038
+
+
+.. autofunction:: execute_batch
+
+ .. versionadded:: 2.7
+
+.. note::
+
+ `!execute_batch()` can be also used in conjunction with PostgreSQL
+ prepared statements using |PREPARE|_, |EXECUTE|_, |DEALLOCATE|_.
+ Instead of executing::
+
+ execute_batch(cur,
+ "big and complex SQL with %s %s params",
+ params_list)
+
+ it is possible to execute something like::
+
+ cur.execute("PREPARE stmt AS big and complex SQL with $1 $2 params")
+ execute_batch(cur, "EXECUTE stmt (%s, %s)", params_list)
+ cur.execute("DEALLOCATE stmt")
+
+ which may bring further performance benefits: if the operation to perform
+ is complex, every single execution will be faster as the query plan is
+ already cached; furthermore the amount of data to send on the server will
+ be lesser (one |EXECUTE| per param set instead of the whole, likely
+ longer, statement).
+
+ .. |PREPARE| replace:: :sql:`PREPARE`
+ .. _PREPARE: https://www.postgresql.org/docs/current/static/sql-prepare.html
+
+ .. |EXECUTE| replace:: :sql:`EXECUTE`
+ .. _EXECUTE: https://www.postgresql.org/docs/current/static/sql-execute.html
+
+ .. |DEALLOCATE| replace:: :sql:`DEALLOCATE`
+ .. _DEALLOCATE: https://www.postgresql.org/docs/current/static/sql-deallocate.html
+
+
+.. autofunction:: execute_values
+
+ .. versionadded:: 2.7
+
+
+
.. index::
single: Time zones; Fractional