处理大型 ResultSet

Python 中的数据库入门

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

处理大型 ResultSet

  • 使用 fetchmany() 指定要处理的行数
  • 可循环调用 fetchmany()
  • 无更多记录时返回空列表
  • 之后需关闭 ResultProxy
Python 中的数据库入门

批量获取行

while more_results:

partial_results = results_proxy.fetchmany(50)
if partial_results == []: more_results = False
for row in partial_results: state_count[row.state] += 1
results_proxy.close()
Python 中的数据库入门

开始练习!

Python 中的数据库入门

Preparing Video For Download...