db の単一の行を更新する関数があります。
def update_one_row(conn, condition, value):
with conn.cursor() as curr:
curr.execute("""UPDATE persons p
SET p.age=%s
WHERE p.name=%s;""",
(value, condition))
conn.commit()
この関数を複数回 (数千回) 使用して、後で次のようにしても問題ありませんか。
from pymysql import Connect
connect_args = {...}
conn = Connect(**connect_args)
for condition, value in iterable_of_conditions_values:
update_one_row(conn, condition, value)
# Here I visually inspect in jupyter notebook if things went as expected and I accidentaly did not screw up
conn.commit()
または、 tocurr
の代わりに渡す必要がありますか?conn
update_one_row
私は知ってcurr.executemany()
いますが、明示的なループを好みます。性能差はありますか?
全体的に、カーソルの使用法といつコミットするかについてかなり迷っています。