I've got a table with 9 columns, the first three are all text and the last 6 are setup as INT's.
When I insert into the text fields everything works as expected
conn = pymysql.connect(host='', port=, user='', passwd='', db='')
cur = conn.cursor()
cur.execute("INSERT INTO table(Name) VALUES ('Sample Name')")
That code runs fine, and allows me to insert the name into my database. However, when running an insert statement for my integer stuff I am in all kinds of trouble.
I've tried all of the following:
cur.execute("INSERT INTO table(Left Avg) VALUES (5)")
cur.execute("INSERT INTO table(Left Avg) VALUES (%s)", (5))
cur.execute("INSERT INTO table(Left Avg) VALUES (%s)" % (5))
cur.execute("""INSERT INTO mlb_data(Left Avg) VALUES (%s)""" % (5))
Essentially no matter what I try when inserting my integer into the table I get the following error.
Traceback (most recent call last):
File "testing.py", line 12, in <module>
cur.execute("""INSERT INTO mlb_data(Left Avg) VALUES (%s)""" % (5))
File "build/bdist.macosx-10.7-intel/egg/pymysql/cursors.py", line 117, in execute
File "build/bdist.macosx-10.7-intel/egg/pymysql/connections.py", line 189, in defaulterrorhandler
pymysql.err.ProgrammingError: (1064, u"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 'Left Avg) VALUES (5)' at line 1")
I have tried to change the MySQl tablet to be a VarChar rather than an INT, but regardless anytime I try to insert a number I get an error.
What am I missing here?
EDIT: I don't know if I didn't try this before or if my formatting was incorrect but I figured it out.
num = 5.23947824987
cur.execute("INSERT INTO mlb_data(LeftAvg) VALUES (%s)", (num,))
Works without a hitch. Is this correct, or did I just get very lucky?