]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
docs: improve basic usage example
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 27 Mar 2025 11:05:25 +0000 (12:05 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Thu, 27 Mar 2025 11:05:25 +0000 (12:05 +0100)
Be consistent with return/print, make the second print actually print
something (taking the chance to showcase `executemany()`).

docs/basic/usage.rst

index b4630ef348591d6a93bc8edf4bd055ef23c4b1f5..a3bb13e7b329c1d83c826a09942b840841225a43 100644 (file)
@@ -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)