SQL连接问题。编程:提供的绑定数量不正确。当前语句使用10,提供了120个
我已经看到有很多这样的帖子。我还考虑了有关帖子的反馈,但是关于绑定数量不正确的新错误。
我在SQL上创建了一个表
conn = sqlite3.connect('AQM_2022.db')
c = conn.cursor()
c.execute('''CREATE TABLE Reg2
(CPI,
UNR INT NOT NULL,
M1 INT NOT NULL,
M2 INT NOT NULL,
IMP INT NOT NULL,
EXP INT NOT NULL,
RetailSales INT NOT NULL,
GBBalance INT NOT NULL,
PPI INT NOT NULL,
const INT)''')
print("Table created successfully")*
,我想将以下数字导出到我的SQL数据库:
index1=dfGB.index.strftime('%Y-%m-%d %H-%M-%S')
dfGB['Date1']=index1
dfGB.head(5)
我将其转换为列表,
records_to_insert = dfGB.values.tolist()
records_to_insert
但是当我想将其导出到SQL:
c = conn.cursor()
c.executemany("INSERT INTO Reg2(CPI,UNR,M1,M2,IMP,EXP,RetailSales,GBBalance,PPI,const) VALUES (?,?,?,?,?,?,?,?,?,?)", [records_to_insert])
conn.commit()
con.close()
以下错误弹出: 编程:提供的绑定数量不正确。当前语句使用10,提供了120个。
有人知道问题吗?
最好的标准
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要提供一排列表到:
您正在提供120个值的平面列表。
按照行的内容
应为您提供10个项目列表的正确列表。
如果您的列表进入了百万个元素,则可能需要进行迭代划分,而不是创建一个新列表:您如何将列表拆分为均匀尺寸的块?
You need to provide a list of rows to sqlite3.Cursor.executemany:
You are providing a flat list of 120 values.
Something along the lines of
should provide you with a correctly chunked list of list of 10 items each.
If your list goes into million of elements you may want to chunk iteratively instead of creating a new list: How do you split a list into evenly sized chunks?