3

I have this list

info=[[u' Rasta.eon 2 - 1 Rasta.Xd   ', u'Razer CS:GO Tournament 2', u'26-02-2014'], [u' XPC 1       - 2 WP.GG  ', u'Roccat DotA 2 Tournament', u'26-02-2014']]

conn= MySQLdb.connect(host='localhost',user='root',passwd='',db='ee')

c = conn.cursor()
query = "INSERT INTO todaysmatches (match,tournamentname,matchdate) VALUES (%s,%s,%s)"
c.executemany(query, info)
conn.commit()
conn.close()

when I try to execute the query I get this error

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 'match,tournamentname,matchdate) VALUES \n(' Rasta.eon 2 - 1 Rasta.Xd   ','Razer C' at line 1")

match is varchar(150),tournamentname is varchar(150),matchdate is DATE

2 Answers 2

3

match is a keyword in MySQL. You can use it as a column name if you backquote it

INSERT INTO todaysmatches (`match`,tournamentname,matchdate) VALUES (%s,%s,%s)

but it would be more convenient if you chose some other name for this column.


Look at what happens when you try to create a table with a column called match:

mysql> create table foo (match varchar(150), tournamentname varchar(150), matchdate DATE);
ERROR 1064 (42000): 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 'match varchar(150), tournamentname varchar(150), matchdate DATE)' at line 1
mysql> create table foo (`match` varchar(150), tournamentname varchar(150), matchdate DATE);
Query OK, 0 rows affected (0.03 sec)
Sign up to request clarification or add additional context in comments.

1 Comment

Oh yes. 26-02-2014 should be 2014-02-26.
0

Modify your fourth line to:

query = "INSERT INTO todaysmatches (`match`,`tournamentname`,`matchdate`) VALUES (%s,%s,%s)"

Comments

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.