在sql.executemany(...附近的语法错误'('

时间:2015-01-28 14:43:01

标签: python mysql pymssql executemany

我尝试在python中执行以下代码,但导致syntax error near '('出现executemany(..)错误。当我从sql中删除名称并只写%s时,也会导致错误there are more placeholders thant the variables 有谁知道我怎么解决它?

upInfo ={"aa": "aaa","bb": "bbb","cc": "ccc"}
sql = 'UPDATE table SET a=  %(aa)s WHERE b= %(bb)s and c= %(cc)s'
con = pymssql.connect(...)
con.autocommit(True)
cur = con.cursor()
cur.executemany(sql, upInfo)

1 个答案:

答案 0 :(得分:0)

由于这是executemany(),因此它应该是词典列表:

upInfo = [{"aa": "aaa", "bb": "bbb", "cc": "ccc"}]

或者,使用常规execute()

cur.execute(sql, upInfo)