如何计算python中插入的行数?
我有一个数据库连接,我使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如@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()