diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-03 04:56:02 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-03 04:56:02 +0000 |
| commit | de8b335d80ecba0305e2b4796373a4064fd450b3 (patch) | |
| tree | 26a5fab1a9f022adda5d5ad2de78b816fe0350e1 /doc/src/extras.rst | |
| parent | a8a3a298f8ade3b0430ff2df0a5d5ee1fe920e3d (diff) | |
| parent | ca42306d7916647448184907e03c77ff54ebd4f9 (diff) | |
| download | psycopg2-sql-compose.tar.gz | |
Merge branch 'master' into sql-composesql-compose
Diffstat (limited to 'doc/src/extras.rst')
| -rw-r--r-- | doc/src/extras.rst | 57 |
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 |
