diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-01 01:59:47 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2017-02-01 01:59:47 +0000 |
| commit | a95fd3df1abc0282f1c47fa2170191f037c3c8de (patch) | |
| tree | 0a7b16892e886f88f48b34f05c6f57508d2e972e /doc/src | |
| parent | 8ac839ce9564cefa6e9134339774b39badaa5ab2 (diff) | |
| download | psycopg2-a95fd3df1abc0282f1c47fa2170191f037c3c8de.tar.gz | |
Added execute_batch and execute_values functions
Diffstat (limited to 'doc/src')
| -rw-r--r-- | doc/src/cursor.rst | 17 | ||||
| -rw-r--r-- | doc/src/extras.rst | 25 |
2 files changed, 36 insertions, 6 deletions
diff --git a/doc/src/cursor.rst b/doc/src/cursor.rst index aee6b46..4161f2a 100644 --- a/doc/src/cursor.rst +++ b/doc/src/cursor.rst @@ -172,33 +172,38 @@ The ``cursor`` class .. method:: execute(operation [, parameters]) - + Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Variables are specified either with positional (``%s``) or named (:samp:`%({name})s`) placeholders. See :ref:`query-parameters`. - + The method returns `!None`. If a query was executed, the returned values can be retrieved using |fetch*|_ methods. .. method:: executemany(operation, seq_of_parameters) - + Prepare a database operation (query or command) and then execute it against all parameter tuples or mappings found in the sequence `seq_of_parameters`. - + The function is mostly useful for commands that update the database: any result set returned by the query is discarded. - + Parameters are bounded to the query using the same rules described in the `~cursor.execute()` method. + .. warning:: + In its current implementation this method is not faster than + executing `~cursor.execute()` in a loop. For better performance + you can use the functions described in :ref:`fast-exec`. + .. method:: callproc(procname [, parameters]) - + Call a stored database procedure with the given name. The sequence of parameters must contain one entry for each argument that the procedure expects. Overloaded procedures are supported. Named parameters can be diff --git a/doc/src/extras.rst b/doc/src/extras.rst index d33b8ee..66be590 100644 --- a/doc/src/extras.rst +++ b/doc/src/extras.rst @@ -974,6 +974,31 @@ 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 + +.. autofunction:: execute_values + + .. versionadded:: 2.7 + + + .. index:: single: Time zones; Fractional |
