INSERT上的SQL语法错误

时间:2012-04-25 21:46:49

标签: python mysql sql

我从以下声明中继续遇到错误:

cursor.execute("""INSERT into financial_statements (url) 
                  VALUES (%s) WHERE provider=%s AND date=%s""", (url, provider, date))

我得到的错误是:

_mysql_exceptions.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 
'WHERE provider='ANGEL' AND date='2012-03-01'' at line 2")

2 个答案:

答案 0 :(得分:5)

INSERT语句不能有WHERE子句。

也许你打算进行更新?

UPDATE financial_statements
SET url = %s
WHERE provider=%s AND date=%s

答案 1 :(得分:4)

WHERE语句中使用INSERT没有任何意义 - 没有任何限制。

如果要修改现有行,请使用UPDATE

UPDATE financial_statements SET url=%s WHERE provider=%s and DATE=%s