如何计算python中插入的行数?

发布于 2025-01-26 07:28:32 字数 369 浏览 1 评论 0原文

我有一个数据库连接,我使用to_sql插入数据。

xls.to_sql(table, con=engine, if_exists='append', index=False, chunksize=10000)

我一直在尝试获取插入的行数或表中的行数(考虑到在插入新数据之前将表截断)。我一直没有成功。

你能帮忙吗?

我已经尝试过:

countRow=engine.execute("select count(*) from "+table);
print(countRow)

我觉得这不起作用很奇怪,因为我使用同样的东西来截断表。我在这里错过了什么或在这里做错了什么?

I have a database connection and I insert data into a table using to_sql.

xls.to_sql(table, con=engine, if_exists='append', index=False, chunksize=10000)

I've been trying to obtain the number of rows inserted, or the number of rows in the table (considering I truncate the table before inserting new data). I've been unsuccessful though.

Can you help?

I've tried:

countRow=engine.execute("select count(*) from "+table);
print(countRow)

I find it odd that this doesn't work because I use the same thing to truncate the table. Am I missing something or doing something wrong here?

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

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

发布评论

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

评论(1

梦途 2025-02-02 07:28:32

正如@deepak Tripathi所建议的那样,我使用了此功能,并且它起作用:

Engine.execute(“ select count(*)来自“+ table+”;“)。fetchall()

As @Deepak Tripathi suggested, I used this and it worked:

engine.execute("select count(*) from "+table+ ";").fetchall()

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