trinodb / trino-python-client

Python client for Trino
Apache License 2.0
307 stars 150 forks source link

fetchall doesn't respect the cursor position #414

Closed boiledfroginthewell closed 8 months ago

boiledfroginthewell commented 9 months ago

Expected behavior

After some rows are fetched, fetchall() should return remaining rows as PEP-0249 says:

https://peps.python.org/pep-0249/#fetchall Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor’s arraysize attribute can affect the performance of this operation.

Actual behavior

fetchall() returns all the rows.

Steps To Reproduce

cur = conn.cursor()
cur.execute("SELECT * FROM ( VALUES (1), (2), (3), (4), (5), (6))")
print(cur.fetchmany(2))
print(cur.fetchall()) # should return 4 rows
print(cur.fetchmany(10)) # should return no rows

Actual Outputs:

[[1], [2]]
[[1], [2], [3], [4], [5], [6]]
[[3], [4], [5], [6]]

Expected Outputs:

[[1], [2]]
[[3], [4], [5], [6]]
[]

Log output

No response

Operating System

Manjaro Linux

Trino Python client version

0.327.0

Trino Server version

427

Python version

3.11.5

Are you willing to submit PR?