From aabac5df31a764b812f6113a1b18d18974a61768 Mon Sep 17 00:00:00 2001 From: Hannes Date: Mon, 10 Oct 2022 19:08:46 +0200 Subject: Add executemany & execute_batch examples --- doc/src/cursor.rst | 6 ++++++ doc/src/extras.rst | 6 ++++++ 2 files changed, 12 insertions(+) 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:: -- cgit v1.2.1