如何加快数据库中数据的更新速度?是否需要更改循环或以其他方式生成更新?
try:
g = 1
for i in gate_io().values.tolist():
with connection.cursor() as cursor:
if i[1] != 0 and i[1] != '':
insert_quarry = "UPDATE gate SET symbol = %s, bidPX = %s, askPx = %s WHERE id = %s"
currency = [i[0], i[1], i[2]]
cursor.execute(insert_quarry, (currency[0], currency[1], currency[2], g))
connection.commit()
g = g + 1
else:
continue
finally:
connection.close()
有没有可能使用NumPy来完成这个任务?或者有没有其他的选择?
1条答案
按热度按时间8yoxcaq71#
不要在每次UPDATE后提交,而是在每次100次左右的批处理后提交,大多数实际的更新工作都发生在提交时。
不要忘记提交最后一批。