Iterating over PyoDBC result without fetchall()

可紊 提交于 2020-01-01 05:04:33

问题


I'm trying to process a very large query with pyodbc and I need to iterate over the rows without loading them all at once with fetchall().

Is there a good and principled way to do this?


回答1:


Sure - use a while loop with fetchone.

http://code.google.com/p/pyodbc/wiki/Cursor#fetchone

row = cursor.fetchone()
while row is not None:
    # do something
    row = cursor.fetchone()



回答2:


you could also use cursor.fetchmany() if you want to batch up the fetches (defaults to 1 if you don't override it)

http://code.google.com/p/pyodbc/wiki/Cursor#fetchmany



来源:https://stackoverflow.com/questions/17707264/iterating-over-pyodbc-result-without-fetchall

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!