adiyansjah opened a new issue, #4999:
URL: https://github.com/apache/arrow-adbc/issues/4999
### What happened?
The PostgreSQL driver wraps a query as `COPY (<query>) TO STDOUT (FORMAT
binary)` when it fetches with COPY, which is the default. Before wrapping,
`PqResultHelper::ExecuteCopy` removes trailing semicolons, but only when `;` is
the very last character:
```cpp
// c/driver/postgresql/result_helper.cc (main)
while (!query_.empty() && query_.back() == ';') {
query_.pop_back();
}
std::string copy_query = "COPY (" + query_ + ") TO STDOUT (FORMAT binary)";
```
A query whose `;` is followed by whitespace, for example `"SELECT 1;\n"`
(common when SQL is read from a file), is therefore wrapped as `COPY (SELECT
1;\n) TO STDOUT (FORMAT binary)`, which PostgreSQL rejects with a syntax error
(42601). The same query works with `adbc.postgresql.use_copy=false`, and it
works with psql, psycopg and JDBC.
#1147 fixed the case of a trailing `;`. This is the remaining case of `;`
followed by whitespace.
### How can we reproduce the bug?
Driver 1.13.0 (`adbc-driver-postgresql` from PyPI, ADBC Libraries 25),
PostgreSQL 17:
```python
import adbc_driver_postgresql.dbapi as pg
with pg.connect("postgresql://postgres@localhost:5432/postgres") as conn:
with conn.cursor() as cur:
cur.execute("SELECT 1;") # works: the trailing ';' is stripped
print(cur.fetchall())
cur.execute("SELECT 1;\n") # fails: COPY (SELECT 1;\n) TO STDOUT
... -> syntax error at or near ";"
print(cur.fetchall())
```
A possible fix is to strip trailing whitespace together with semicolons,
e.g. loop while the last character is `;` or an ASCII space, tab, CR or LF.
### Environment/Setup
adbc-driver-postgresql 1.13.0 (Python), PostgreSQL 17.11, Linux x86-64. The
code above is unchanged on `main`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]