我是新来的,对Mysql和Python非常陌生。我对这个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))
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))