From 5efa2b4649e51c142ce26a3ab8f74db74d559609 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 27 Mar 2025 12:05:25 +0100 Subject: [PATCH] docs: improve basic usage example Be consistent with return/print, make the second print actually print something (taking the chance to showcase `executemany()`). --- docs/basic/usage.rst | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/basic/usage.rst b/docs/basic/usage.rst index b4630ef34..a3bb13e7b 100644 --- a/docs/basic/usage.rst +++ b/docs/basic/usage.rst @@ -49,11 +49,17 @@ Here is an interactive session showing some of the basic commands: # Query the database and obtain data as Python objects. cur.execute("SELECT * FROM test") - cur.fetchone() - # will return (1, 100, "abc'def") + print(cur.fetchone()) + # will print (1, 100, "abc'def") + + # You can use `cur.executemany()` to perform an operation in batch + cur.executemany( + "INSERT INTO test (num) values (%s)", + [(33,), (66,), (99,)]) # You can use `cur.fetchmany()`, `cur.fetchall()` to return a list # of several records, or even iterate on the cursor + cur.execute("SELECT id, num FROM test order by num") for record in cur: print(record) -- 2.47.2