diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2022-10-20 21:33:46 +0200 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2022-10-20 21:33:46 +0200 |
commit | 20bb48666312e6f4747d1f6187f520c812f29591 (patch) | |
tree | a3da52321cbb942dd8ed75b2aeea77cc6ea71583 | |
parent | 4912be0e7f527e2a025067e16bd2390b09f71d9c (diff) | |
parent | f401d0b738e05911b2a97a933b36fcbf23aba4d2 (diff) | |
download | psycopg2-20bb48666312e6f4747d1f6187f520c812f29591.tar.gz |
Merge branch 'doc_examples_executemanybatch'
-rw-r--r-- | doc/src/cursor.rst | 8 | ||||
-rw-r--r-- | doc/src/extras.rst | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/doc/src/cursor.rst b/doc/src/cursor.rst index a0d66bc..a998b3c 100644 --- a/doc/src/cursor.rst +++ b/doc/src/cursor.rst @@ -208,6 +208,14 @@ The ``cursor`` class Parameters are bounded to the query using the same rules described in the `~cursor.execute()` method. + .. code:: python + + >>> nums = ((1,), (5,), (10,)) + >>> cur.executemany("INSERT INTO test (num) VALUES (%s)", nums) + + >>> tuples = ((123, "foo"), (42, "bar"), (23, "baz")) + >>> cur.executemany("INSERT INTO test (num, data) VALUES (%s, %s)", tuples) + .. warning:: In its current implementation this method is not faster than executing `~cursor.execute()` in a loop. For better performance diff --git a/doc/src/extras.rst b/doc/src/extras.rst index 96f801b..083379b 100644 --- a/doc/src/extras.rst +++ b/doc/src/extras.rst @@ -1029,6 +1029,14 @@ parameters. By reducing the number of server roundtrips the performance can be .. autofunction:: execute_batch + .. code:: python + + >>> nums = ((1,), (5,), (10,)) + >>> execute_batch(cur, "INSERT INTO test (num) VALUES (%s)", nums) + + >>> tuples = ((123, "foo"), (42, "bar"), (23, "baz")) + >>> execute_batch(cur, "INSERT INTO test (num, data) VALUES (%s, %s)", tuples) + .. versionadded:: 2.7 .. note:: |