【问题标题】:Getting Error while Inserting a row to MYSQL using Python使用 Python 向 MYSQL 插入行时出错
【发布时间】: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 中的关键字。我对吗 ?如果是,那么任何人都可以帮助我解决这个问题。 谢谢

【问题讨论】:

标签: mysql-connector mysql-connector-python


【解决方案1】:

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

这是list of the reserved keywords in MySQL

为避免此问题,只需在关键字周围添加反引号 (`)。

【讨论】:

    猜你喜欢
    • 2022-12-15
    • 1970-01-01
    • 2019-10-25
    • 1970-01-01
    • 2018-06-01
    • 2016-10-25
    • 2013-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多