这个python mysql查询有什么问题

时间:2014-06-23 11:46:41

标签: python mysql

我正在编写一个需要在db

中插入值的脚本

我写过像

这样的查询
cur.execute('''INSERT into agent_info set (didNo,agentNumber,agentOrder,agentName,agentId,agentEmail,dateOfCreation,agentStatus,) values (%s,%s,%s,%s,%s,%s,%s,%s) ''',(row[0],row[2],'1','SomeName',id_generator(),'hey',ti,'FREE'))

但我在agentStatus

附近收到错误消息

这是错误:

ProgrammingError(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(didNo,agentNumber,agentOrder,agentName,agentId,agentEmail,dateOfCreation,agentS' at line 1")

1 个答案:

答案 0 :(得分:1)

您的逗号太多,需要删除 set

INSERT into agent_info set
--                     ^^^
(didNo,agentNumber,agentOrder,agentName,agentId,
 agentEmail,dateOfCreation,agentStatus,)
--                          ----------^
values (%s,%s,%s,%s,%s,%s,%s,%s)

更正声明:

INSERT into agent_info
(didNo,agentNumber,agentOrder,agentName,agentId,
 agentEmail,dateOfCreation,agentStatus)
values (%s,%s,%s,%s,%s,%s,%s,%s)

SET只应在MySQL INSERT INTO <table> SET col1=val1, col2=val2非标准SQL扩展中使用。