diff options
author | Hannes <kannes@users.noreply.github.com> | 2022-10-10 19:08:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-10 19:08:46 +0200 |
commit | aabac5df31a764b812f6113a1b18d18974a61768 (patch) | |
tree | 13c91233b557a0e71155694f032f88902d9820aa | |
parent | a12dbc435734e592621a760cc32142e77c6e4883 (diff) | |
download | psycopg2-aabac5df31a764b812f6113a1b18d18974a61768.tar.gz |
Add executemany & execute_batch examples
-rw-r--r-- | doc/src/cursor.rst | 6 | ||||
-rw-r--r-- | doc/src/extras.rst | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/doc/src/cursor.rst b/doc/src/cursor.rst index a0d66bc..b5b2990 100644 --- a/doc/src/cursor.rst +++ b/doc/src/cursor.rst @@ -207,6 +207,12 @@ The ``cursor`` class Parameters are bounded to the query using the same rules described in the `~cursor.execute()` method. + + >>> 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 diff --git a/doc/src/extras.rst b/doc/src/extras.rst index 96f801b..30c8a6b 100644 --- a/doc/src/extras.rst +++ b/doc/src/extras.rst @@ -1029,6 +1029,12 @@ parameters. By reducing the number of server roundtrips the performance can be .. autofunction:: execute_batch + >>> 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:: |