Steven Matthews
Steven Matthews

Reputation: 11275

Getting MySQL Error

Trying to run a MySQL script via Python and it keeps giving me errors. Here is my MySQL:

c.execute("""INSERT into DATA(checkup_date)
VALUES(%s) WHERE machine_name = %s
""", (date, machine))

What am I doing wrong?

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 machine_name = 'TL-D04'\nVALUES('2011-11-11')' at line 2")

Upvotes: 1

Views: 76

Answers (2)

Luke Woodward
Luke Woodward

Reputation: 64949

INSERT INTO ... VALUES ... WHERE ... isn't valid SQL. You can't add a WHERE clause to an INSERT statement.

I'm guessing you want to update the checkup_date column for a row currently in the DATA table, as opposed to inserting a new row. If that's the case, try

UPDATE DATA SET checkup_date = %s WHERE machine_name = %s

instead.

Upvotes: 3

Alfabravo
Alfabravo

Reputation: 7569

This thread should help you.

cursor.execute("INSERT INTO im_entry.test ("+entrym+") VALUES ('"+p+"');")

Looks like you have too many quotation marks

Upvotes: 0

Related Questions