首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Python向MYSQL插入行时出错

问使用Python向MYSQL插入行时出错
EN

Stack Overflow用户
提问于 2020-08-29 17:54:04
回答 1查看 48关注 0票数 0

我正在尝试使用python在mysql表中添加一行。

代码语言:javascript
复制
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))

我得到了这个错误,

代码语言:javascript
复制
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中是一个关键字。我说的对吗?如果是,那么任何人可以帮助我解决这个问题。谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-08-29 20:39:47

您正在使用关键字return作为字段名称。这可能就是为什么在SQL语句那一部分附近出现错误的原因。

这是一个list of the reserved keywords in MySQL。

为了避免这个问题,只需在关键字周围添加反引号(`)即可。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63645649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档