2

I am searching for the correct syntax for using server-side cursors when using the orm version (http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#creating-a-session) of sqlaclhemy.

E.g.

session = SessionMaker()
res = session.query(MyModel).filter(MyModel.date.between(odate, cdate))

for obj in res:
    append_to_disk(obj)

I've tried:

stream_sessionmaker = sessionmaker(
    pg_engine.connect().execution_options(stream_results=True)
)
session = stream_sessionmaker()

to no avail. The documentation seams to only document the Core version (http://docs.sqlalchemy.org/en/latest/core/tutorial.html) (http://docs.sqlalchemy.org/en/latest/core/connections.html#sqlalchemy.engine.Connection.execution_options.params.stream_results)

1 Answer 1

4

You're looking for yield_per:

res = session.query(MyModel).filter(MyModel.date.between(odate, cdate)).yield_per(1000)
Sign up to request clarification or add additional context in comments.

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.