0

I have the following python code:

now = time.strftime('%Y-%m-%d %H:%M:%S')
#now = datetime.datetime.now()
query = """INSERT INTO bandwidth_by_second (current_time, down, up)  VALUES (%s, %s, %s)"""
data = (now, 1.0, 2.0)
cursor.execute(query, data)

My schema for this table is:

  • current_time - datatime
  • down - double
  • up - double

When running this, I get the following error:

_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 'current_time, down, up) VALUES ('2014-10-27 18:29:32', 1, 1)' at line 1")

I had thought I had formatted the date time wrong, but this post suggests otherwise.

What the heck is going on?

2 Answers 2

3

Use '%s' in quotes. It will work then :)

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

1 Comment

I see other answers that suggest the same thing. When I do that query = """INSERT INTO bandwidth_by_second (current_time, down, up) VALUES ('%s', %s, %s)""", the resultant error looks like (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 'current_time, down, up) VALUES (''2014-10-28 08:11:52.306849'', 1, 1)' at line 1")
1

It had to do with the column name in the database table. I changed current_timeto currenttime and it started working.

1 Comment

You are a god to me. I just spent several hours trying to figure this out. Thank you so much!

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.