David542
David542

Reputation: 110093

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

Upvotes: 2

Views: 191

Answers (2)

ThiefMaster
ThiefMaster

Reputation: 318478

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

Upvotes: 4

Mark Byers
Mark Byers

Reputation: 837996

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

Upvotes: 5

Related Questions