Python MySQLdb编程错误:插入数据时为1064 [英] Python MySQLdb Programming Error: 1064 when inserting data
本文介绍了Python MySQLdb编程错误:插入数据时为1064的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有此列表
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是varchar(150),比赛名称是varchar(150),matchdate是DATE
match is varchar(150),tournamentname is varchar(150),matchdate is DATE
推荐答案
match
是MySQL中的关键字.如果将其反引号,则可以将其用作列名
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.
看看当您尝试创建带有名为match
的列的表时会发生什么:
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)
这篇关于Python MySQLdb编程错误:插入数据时为1064的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文