SQL连接问题。编程:提供的绑定数量不正确。当前语句使用10,提供了120个

发布于 2025-01-31 01:10:47 字数 1475 浏览 2 评论 0 原文

我已经看到有很多这样的帖子。我还考虑了有关帖子的反馈,但是关于绑定数量不正确的新错误。

我在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个。

有人知道问题吗?

最好的标准

“

”数据列表“

I have seen there are a lot of posts like this. I have also considered the feedback on the posts but there is a new error regarding incorrect number of bindings.

I created a table on 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")*

And i want to export following numbers to my SQL database:

index1=dfGB.index.strftime('%Y-%m-%d %H-%M-%S')
dfGB['Date1']=index1
dfGB.head(5)

I converted it into lists

records_to_insert = dfGB.values.tolist()
records_to_insert

But when i want to export it to 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()

The following error pops up:
ProgrammingError: Incorrect number of bindings supplied. The current statement uses 10, and there are 120 supplied.

Does somebody know what the problem could be?

Best regards

Data dfGB

data to list

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一刻暧昧 2025-02-07 01:10:47

您需要提供一排列表到

您正在提供120个值的平面列表。

按照行的内容

recs = dfGB.values.tolist()
recs = [recs [v:v+10] for v in range(0,len(recs), 10]

应为您提供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

recs = dfGB.values.tolist()
recs = [recs [v:v+10] for v in range(0,len(recs), 10]

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文