This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 97ef0fa623 docs(python): fix out of date statement in cookbook (#4961)
97ef0fa623 is described below
commit 97ef0fa62306ebc8874c9374a44e404b90fa138c
Author: Bryce Mecum <[email protected]>
AuthorDate: Tue Oct 27 16:04:52 2026 -0700
docs(python): fix out of date statement in cookbook (#4961)
I found this out of date statement in the cookbook:
> Right now, the PostgreSQL driver only supports bind parameters for
queries that don't generate result sets.
I think since https://github.com/apache/arrow-adbc/pull/2065 this has
been fixed.
This PR removes that note and also reworks the cookbook to make it clear
what all you can do.
---
docs/source/python/recipe/postgresql_execute_bind.py | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/docs/source/python/recipe/postgresql_execute_bind.py
b/docs/source/python/recipe/postgresql_execute_bind.py
index 0d47173d77..aae7435085 100644
--- a/docs/source/python/recipe/postgresql_execute_bind.py
+++ b/docs/source/python/recipe/postgresql_execute_bind.py
@@ -20,8 +20,6 @@
# RECIPE STARTS HERE
#: ADBC allows using Python and Arrow values as bind parameters.
-#: Right now, the PostgreSQL driver only supports bind parameters
-#: for queries that don't generate result sets.
import os
@@ -39,7 +37,7 @@ with conn.cursor() as cur:
conn.commit()
-#: We can bind Python values:
+#: We can bind Python values to ``INSERT`` statements:
with conn.cursor() as cur:
cur.executemany("INSERT INTO example VALUES ($1, $2)", [(1, 2), (3, 4)])
@@ -50,7 +48,13 @@ with conn.cursor() as cur:
#: libraries like psycopg use for bind parameters, note that this
#: is not supported—only the PostgreSQL-native ``$1`` syntax.
-#: We can also bind Arrow values:
+#: We can also bind Python values to ``SELECT`` queries:
+with conn.cursor() as cur:
+ cur.execute("SELECT ints, bigints FROM example WHERE ints > $1 ORDER BY
ints", (1,))
+ assert cur.fetchall() == [(3, 4)]
+
+#: We can also bind Arrow values instead of Python values. ``executemany()``
+#: executes an ``INSERT`` for each record in the ``RecordBatch``:
with conn.cursor() as cur:
data = pyarrow.record_batch(
[
@@ -64,4 +68,12 @@ with conn.cursor() as cur:
cur.execute("SELECT SUM(ints) FROM example")
assert cur.fetchone() == (15,)
+#: Use ``execute()`` to bind the same batch to a ``SELECT`` query and collect
+#: the results. ``executemany()`` does not return a result set.
+with conn.cursor() as cur:
+ cur.execute(
+ "SELECT ints, bigints FROM example WHERE ints = $1 AND bigints = $2",
data
+ )
+ assert cur.fetchall() == [(5, 7), (6, 8)]
+
conn.close()