1

私はリストのリストを持っています:myList = [[123, 345], [23, 45], [54, 34]]

私はこのようなことをしたい:

cursor.executemany("update tablename set flag = 'yes' where id = %s and officeid = %s", myList)

これを検索しましたが、解決策が見つかりませんでした。実装されない場合、リスト内のすべての要素をループする必要のない、より良い更新ステートメントは何ですか?

4

2 に答える 2

1
update tablename set flag = 'yes' 
WHERE (id,officeid) IN ((123,345), (23,45), (54,34));
于 2012-05-10T16:18:11.477 に答える
1
myTuples = tuple(map(tuple, myList))

cursor.execute("update tablename set flag = 'yes' \
where (id, officeid) in " + str(myTuples))
于 2012-05-10T16:28:18.990 に答える