首页 > 解决方案 > 更新 10,000 条记录 - 最好的方法是什么

问题描述

我需要更新 10,000 条记录,我想知道最快的方法是什么,这就是我目前正在做的事情

我得到了我需要更新的所有记录,一个大的 sku 列表。然后我遍历该列表并更新它们。在下面

in_both 是我循环遍历的 skus 列表,在 ShopReconciliation 中获取参考并更新

for line_item, sku enumerate(in_both):
    got_products = ShopReconciliation.objects.filter(sku=sku, run_id=self.reconciliation_id)
    for got_product in got_products:
        got_product.in_es = True
        got_product.save()

这行得通,但让我震惊的是它不是很快。我可以有 60k 条记录

有这么多记录有更好的方法吗

谢谢

标签: python-2.7

解决方案


cursor.executemany大多数库都支持cx_Oraclepyodbc。可以检查数据库和数据访问库以了解该功能的可用性。


推荐阅读