pymonetdb icon indicating copy to clipboard operation
pymonetdb copied to clipboard

Properly handle multiple result sets

Open joerivanruth opened this issue 2 years ago • 1 comments

Pymonetdb cannot handle it when you send multiple SQL statements in a single call to Cursor.execute().

For example,

q = """
SELECT value FROM sys.generate_series(0,5);
SELECT value from sys.generate_series(10,15);
"""
cursor.execute(q)
print(cursor.fetchall())

This only yields the result of the second query:

[(10,), (11,), (12,), (13,), (14,)]

More subtly, if the result sets are larger, for example generate_series(0,1000) and generate_series(2000,2000), pymonetdb closes the second result set but not the first result set. The first result set is only dropped when the connection is closed. This can cause the server to run out of storage if the connection is long running, see MonetDB issue 7357.

joerivanruth avatar Feb 13 '23 13:02 joerivanruth

not having the nextset operator sort of is an hint to the user the multi resultsets aren't support (unfortunately we cannot force single statements).

njnes avatar Jul 31 '23 19:07 njnes

This has been fixed in release 1.8.0. Pymonetdb now initially returns the first result set rather than the last, and you can use nextset to retrieve the others.

joerivanruth avatar Jul 10 '24 14:07 joerivanruth