c:postgres: support Postgres Arrays in parameter binding
- Dominant language
- C#
- Stars
- 627
- Forks
- 217
- Avg merge
- 17h
- Merged PRs (30d)
- 57
Description
### What feature or improvement would you like to see?
The simplest case of this is something like this called from Python:
```python
cursor.execute('SELECT $1', ([1, 2, 3],))
cursor.fetch_arrow_table()
```
Currently, this results in
```
Traceback (most recent call last):
File "", line 1, in
File "/.venv/lib/python3.12/site-packages/adbc_driver_manager/dbapi.py", line 698, in execute
handle, self._rowcount = _blocking_call(
^^^^^^^^^^^^^^^
File "adbc_driver_manager/_lib.pyx", line 1569, in adbc_driver_manager._lib._blocking_call_impl
File "adbc_driver_manager/_lib.pyx", line 1562, in adbc_driver_manager._lib._blocking_call_impl
File "adbc_driver_manager/_lib.pyx", line 1213, in adbc_driver_manager._lib.AdbcStatement.execute_query
File "adbc_driver_manager/_lib.pyx", line 260, in adbc_driver_manager._lib.check_error
adbc_driver_manager.NotSupportedError: NOT_IMPLEMENTED: [libpq] Field #1 ('0') has unsupported parameter type list
```
Along the same lines it would be nice if PyArrow arrays could be bound similarly like:
```python
cursor.execute('SELECT $1', (pyarrow.array([1, 2, 3]),))
cursor.fetch_arrow_table()
```
```
Traceback (most recent call last):
File "", line 1, in
File "//.venv/lib/python3.12/site-packages/adbc_driver_manager/dbapi.py", line 696, in execute
self._prepare_execute(operation, parameters)
File "/.venv/lib/python3.12/site-packages/adbc_driver_manager/dbapi.py", line 675, in _prepare_execute
rb = pyarrow.record_batch(
^^^^^^^^^^^^^^^^^^^^^
File "pyarrow/table.pxi", line 5828, in pyarrow.lib.record_batch
File "pyarrow/table.pxi", line 3429, in pyarrow.lib.RecordBatch.from_arrays
File "pyarrow/table.pxi", line 1547, in pyarrow.lib._sanitize_arrays
File "pyarrow/table.pxi", line 1528, in pyarrow.lib._schema_from_arrays
File "pyarrow/array.pxi", line 368, in pyarrow.lib.array
File "pyarrow/array.pxi", line 42, in pyarrow.lib._sequence_to_array
File "pyarrow/error.pxi", line 155, in pyarrow.lib.pyarrow_internal_check_status
File "pyarrow/error.pxi", line 92, in pyarrow.lib.check_status
pyarrow.lib.ArrowInvalid: Could not convert
[
1
] with type pyarrow.lib.Int64Array: did not recognize Python value type when inferring an Arrow data type
```
My use case for this is to be able to have a parameterized query which looks something like:
```sql
WITH data (col1, col2) AS (
SELECT UNNEST($1), UNNEST($2)
)
SELECT
col1,
col2,
other_table.some_data
FROM data
JOIN other_table
ON data.col1 = other_table.col1 AND data.col2 = other_table.col2
```
Other simpler but more common query patterns which might use this would be
```sql
SELECT *
FROM table
WHERE table.column = ANY($1)
```
Contributor guide
Assessment
This issue has not been assessed yet.