简体   繁体   中英

SQL syntax error on INSERT

I keep running into an error from the following statement:

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

The error I get is:

_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")

You can't have a WHERE clause for an INSERT statement.

Maybe you meant to perform an UPDATE?

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

It makes no sense to use WHERE in an INSERT statement - there is nothing to restrict.

If you want to modify an existing row, use UPDATE :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM