8

I'm trying to call a stored procedure that returns multiple result sets using SQLAlchemy. If it matters, underneath I'm using PyODBC and FreeTDS. I call the execute() method using a raw query with "exec" calling my stored procedure on a session object and get a ResultProxy object back.

With a raw pyodbc cursor, I can call the nextset() function to advance to the next result set. I see no way to do the same using the ResultProxy I get back from SQLAlchemy. Indeed, the docs say:

The DBAPI cursor will be closed by the ResultProxy when all of its result rows (if any) are exhausted.

Is there a way to read multiple result sets with SQLAlchemy, or will I have to perform this query with the raw DBAPI?

2
  • How did you fix this issue back then? Commented Jun 18, 2021 at 7:42
  • 1
    I worked around it by using a different stored procedure that only had one result set. Commented Jun 19, 2021 at 20:21

2 Answers 2

11

support for nextset() is ticket 1635. It's two years old. It contains a partial patch which needs updating, in particular to work along with an execution option that passes along a hint that the statement will be returning multiple result sets, so that the resultproxy's existing autoclose behavior can remain the default. the feature would also need a lot of tests.

There's no major technical hurdle to this feature but there's generally very little interest in this use case. So at the moment you need to stick with the raw cursor, until people express enough interest in this feature to put momentum behind it again.

Sign up to request clarification or add additional context in comments.

Comments

0

Have you read http://docs.sqlalchemy.org/en/rel_0_7/core/connections.html?highlight=resultproxy#basic-usage ? You can iterate over ResultProxy objects, close them, etc.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.