我正在尝试从csv文件中插入一些行。我看到错误TypeError:并非所有参数都转换为字符串格式。我从这个小查询开始运行,因为csv有90列需要说明。因此,首先,我将其限制在几个专栏中。ProjectId、PlannedStartDate(IST)和2017-7。
如何在PlannedStartDate(IST)中转义括号?我感觉这是错误,因为回溯读取的部分是near '(IST), 2017-7) VALUES ('PRJ278', '10/9/2017', '0')' at line 1"),它告诉我这没有被视为列名的一部分。我尝试了混合使用"和'标记,但到目前为止,没有一种标记工作正常。是重命名列名的唯一可行选项吗?
csv_data = csv.reader(open('C:\\Users\\Public\\Documents\\waterfall_data_test.csv'))
next(csv_data) #skip the header row
for row in csv_data:
cursor.execute(
"INSERT INTO deals.waterfall (ProjectId, PlannedStartDate(IST), 2017-7) VALUES (%s, %s, %s)", row)
db.commit()发布于 2017-11-30 06:53:20
您可以使用`字符转义MySQL中的列名:
cursor.execute(
"INSERT INTO deals.waterfall (`ProjectId`, `PlannedStartDate(IST)`, `2017-7`) VALUES (%s, %s, %s)", rowhttps://stackoverflow.com/questions/47563189
复制相似问题