1

I'm currently getting an error when attempting to update two columns of my MySQL database using mysql.connector and python 3.6. When I execute the command below I get:

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 'order='1' WHERE (match_id='2051673' AND gametime=80 AND event_name='Pass')' at line 1

But, as far as I can tell, my command is perfectly legit. What am I doing incorrectly? Thanks!

for item in pass_list:
    query = """UPDATE events SET event_key=%s AND order=%s 
               WHERE (match_id=%s AND gametime=%s AND event_name=%s)"""
    values = (item[0],item[7],item[1],item[2],item[3])
    cur.execute(query, values)
conn.commit()
conn.close()
10
  • The problem, as it happens, is that order is a SQL keyword. You can put backticks around it: `order`. Commented May 25, 2020 at 16:16
  • Thank you so much! You're right and it never occurred to me, but should have. Commented May 25, 2020 at 16:46
  • You're welcome. The error message isn't particularly helpful in this case, haha. Commented May 25, 2020 at 16:52
  • 1
    If you post the answer I'll assign you credit. Cheers! Commented May 25, 2020 at 18:00
  • 1
    Got it....Needed to use a comma instead of an AND. Correct syntax was "UPDATE events SET events.event_key=%s, events.order_id=%s WHERE".... Commented May 25, 2020 at 18:59

1 Answer 1

1

For good or bad, order is a SQL keyword. You can put backticks around it:

`order`
Sign up to request clarification or add additional context in comments.

1 Comment

this was exactly my problem hehehe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.