0
DB의 단일 행을 업데이트하는 기능이 있습니다.Python DB-Api에서 여러 삽입/업데이트를 커밋해야하는 경우
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()
을 또는 내가 update_one_row
-curr
대신 conn
을 통과해야합니다
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()
을 할 수 있나요?
나는 curr.executemany()
을 알고 있지만, 나는 명백한 루프를 선호한다. 성능 차이가 있습니까?
전반적으로 나는 커서의 사용과 커밋시기에 대해 상당히 분실했습니다.