【发布时间】:2020-08-29 09:54:03
【问题描述】:
我正在尝试使用 python 在 mysql 表中添加一行。
cursor.execute(
"insert into tbl_ft1x2s (match_id, fair_odds, mkt_odds, pred_prob, return, edge, scatter_edge, scatter_trend, hist_prob, smpl_prop) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
(match_id, fair_odds_1, mkt_odds_1, pred_prob_1, exp_return_1, edge_1, scatter_edge, scatter_trend, hist_prob_1,
smpl_prop_1))
我收到了这个错误,
mysql.connector.errors.ProgrammingError: 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 'return, edge, scatter_edge, scatter_trend, hist_prob, smpl_prop) values (87507, ' at line 1
match_id 是 int 而其余所有列都是 varchar。
我认为问题在于“return”列的名称是 MYSQL 中的关键字。我对吗 ?如果是,那么任何人都可以帮助我解决这个问题。 谢谢
【问题讨论】:
-
你能告诉我你究竟想让我在哪里添加双 % 吗?
-
那不行
-
一年前我遇到了你的确切问题(我想......),我知道我需要 %%。看看stackoverflow.com/questions/10678229/… 了解其他想法。顺便说一句,如果您可以避免插入并且只需创建一个新表就可以了,我建议使用 df.to_sql(),请参阅pandas.pydata.org/pandas-docs/stable/reference/api/…。
标签: mysql-connector mysql-connector-python