處理大型 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...