python-2.7 - 更新 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 条记录
有这么多记录有更好的方法吗
谢谢
解决方案
cursor.executemany
大多数库都支持cx_Oracle或pyodbc。可以检查数据库和数据访问库以了解该功能的可用性。
推荐阅读
- python - 如何在python中的每一行之后打印一个小空格
- excel - 如何使用 SPLIT 函数在 VBA 中的用户窗体中搜索多个条目?
- c++ - cpp新手问题:错误:转换为'std :: array
::size_type {aka long unsigned int}' from 'int' 可能会改变结果的符号 - javascript - 命令 `yarn add react-native --exact` 失败
- javascript - 为什么我的代码返回数组的最后一个值,而不是返回每个项目的结果?
- java - Micronaut 和 JUnit 回滚
- android - 如何切换到 Corona SDK 中的另一个场景?
- c# - 使用 LINQ 从数据表中的序列中选择最大值和最小值
- ajax - 如何在 Laravel 中使用 Ajax 单击时验证模态表单
- javascript - 如何使用 javascript 验证 html 代码?