在使用sqlaclhemy的orm版本(http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#creating-a-session)时,我正在搜索使用服务器端游标的正确语法。
E.g。
session = SessionMaker()
res = session.query(MyModel).filter(MyModel.date.between(odate, cdate))
for obj in res:
append_to_disk(obj)
我试过了:
stream_sessionmaker = sessionmaker(
pg_engine.connect().execution_options(stream_results=True)
)
session = stream_sessionmaker()
无济于事。文档接缝仅记录核心版本(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)
答案 0 :(得分:3)
您正在寻找yield_per
:
res = session.query(MyModel).filter(MyModel.date.between(odate, cdate)).yield_per(1000)