python - 连接到 MySQL 时出错 1064 (42000) 尝试插入时
问题描述
我是新来的,对 Mysql 和 Python 非常陌生。我对这个插入语句有疑问:
query = "INSERT INTO {0} (date, open, high, low, close, volume, ivol, hvol) VALUES(%s,%s,%s,%s,%s,%s,%s,%s))".format(str.lower(contract.symbol))
dd = [(20210325, 34.0, 34.03, 33.91, 33.96, 500850, 0, 0), (20210326, 34.57, 34.69, 34.14, 34.53, 480315, 0, 0)]
cursor.executemany(query, dd)
错误是:
Error while connecting to MySQL 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 '),(20210326,34.57,34.69,34.14,34.53,480315,0,0))' at line 1
该表是使用以下语句创建的:
createquery = ("CREATE TABLE {0}( date INT(8) UNSIGNED PRIMARY KEY NOT NULL, open DECIMAL(18,4) NOT NULL, high DECIMAL(18, 4) NOT NULL, low DECIMAL(18,4) NOT NULL, close DECIMAL(18,4) NOT NULL, volume BIGINT NOT NULL, ivol DECIMAL(18,4) NOT NULL,hvol DECIMAL(18,4) NOT NULL)").format(str.lower(contract.symbol))
我花了一整天的时间试图弄清楚这一点。谁能给我指点?
解决方案
你的INSERT
陈述最后有一个太多)
:
query = "INSERT INTO {0} (date, open, high, low, close, volume, ivol, hvol) VALUES(%s,%s,%s,%s,%s,%s,%s,%s))".format(str.lower(contract.symbol))
应该:
query = "INSERT INTO {0} (date, open, high, low, close, volume, ivol, hvol) VALUES(%s,%s,%s,%s,%s,%s,%s,%s)".format(str.lower(contract.symbol))
推荐阅读
- node.js - 如何以正确的方式验证和处理错误?
- python - 是否有用于“信息符号”的 gdb python API?
- java - Branch.io API 在创建时抛出 SSLException Unsupported record version Unknown-0.0
- python - Pandas 根据多个条件对 DataFrame 进行排序
- asp.net-mvc - 无法获得运行 if 语句并转到已登录部分的操作结果
- mysql - 为什么我收到此查询的错误 1054?有没有更有效的方法来编写这个查询?
- javascript - 动画文件输入 Javascript
- swift - 将 INT64 转换为十六进制字符串,去掉两位数?
- python - Chrome 中的嵌入程序不允许生成 Wasm 代码
- windows - 以非管理员身份远程重启服务?