I have a list of absent_studentID_list
absent_studentID_list = ['sid000001','sid000006']
I want to update a column status inside student table which matches the studentID with absent_studentID_list
currently I'm looping over the list and using update
for sid in absent_studentID_list:
u = update(studentTable).values({"status": "Absent"}).where(studentTable.c.studentid == str(sid))
studentTableSession.execute(u)
studentTableSession.commit()
Is there a better way to update than this?
u = studentTable.update().values(status="Absent").where(studentTable.c.studentid.in_(absent_studentID_list))? You should only need to execute it once instead of doing it in a loop.