Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Pandaspd.to_sql()函数有参数if_exists='replace',它删除表并插入给定的DataFrame. 但是我要替换的表是view. 有没有办法替换表并保留视图而不必删除和重新创建它?
pd.to_sql()
if_exists='replace'
DataFrame
view
如果更新具有相同的列。你可以截断表,
con.execute('TRUNCATE table RESTART IDENTITY;')
然后pd.to_sql运行if_exists='append'
pd.to_sql
if_exists='append'