问题描述
Pandas函数to_sql()
的文档可用于DataFrame
对象(请参见 to_sql()
文档)未声明需要(或建议)对连接进行commit()
调用以保持更新.
The documentation for the Pandas function to_sql()
available for DataFrame
objects (see to_sql()
documentation) does not state that a commit()
call on the connection is needed (or recommended) to persist the update.
我可以安全地假设DataFrame.to_sql('table_name', con)
将始终自动提交更改(例如:con.commit()
)吗?
Can I safely assume that DataFrame.to_sql('table_name', con)
will always automatically commit the changes (like in: con.commit()
)?
推荐答案
是的,一天结束时,它将自动提交.
Yes, at the end of the day it will be commited automatically.
熊猫调用SQLAlchemy方法executemany
(用于SQL Alchemy连接):
Pandas calls SQLAlchemy method executemany
(for SQL Alchemy connections):
conn.executemany(self.insert_statement(), data_list)
def run_transaction(self):
cur = self.con.cursor()
try:
yield cur
self.con.commit()
except:
self.con.rollback()
raise
finally:
cur.close()
并且由于 SQL炼金术文档 executemany
最后发出commit
这篇关于Pandas DataFrame.to_sql()函数是否需要后续的commit()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!