python 数据库游标,fetchmany(int),边取数据边处理,防止数量量太大撑爆内存
self.cr.execute(sql, )
# res = self.cr.fetchmany(1000)
while True:
res = self.cr.fetchmany(1000)
print(len(res),res)
if not res:
break
return res
- fetchmany 和
fetchall()类似,只是可以读取指定行数的数据量,当指定数据量小于实际数据量时,可以重复读取 - 如果使用fetchall() 来读取数据,如果数据量太大,放在一个列表中,可能放不下,就可以使用fetchmany()分批读取的方式.
本文来自博客园,作者:那时一个人,转载请注明原文链接:https://www.cnblogs.com/qianxunman/p/13983855.html

浙公网安备 33010602011771号