我正在尝试根据列表中的变量更新字段...
urls = ["aaa", "bbb", "ccc", ...] (long list)
time_now = time.strftime('%Y-%m-%d %H:%M:%S')
UPDATE table SET updated_at=time_now WHERE name IN list
你会如何在python中做到这一点?
到目前为止,这是我的代码:
update_time = time.strftime('%Y-%m-%d %H:%M:%S')
urls = ["http://asdf", "http://qwer"]
cur.execute('UPDATE sales SET updated_at=%s WHERE sale_url IN (%s)', (time_now, urls))
答案 0 :(得分:0)
尝试;
"UPDATE table SET updated_at='%s' WHERE name IN ('%s')" % (time_now, "', '".join(list))