Pandas pd.to_sql()
function has the parameter if_exists='replace'
, which drops the table and inserts the given DataFrame
. But the table I'm trying to replace is part of a view
. Is there a way to replace the table and keep the view without having to delete and recreate it?
Asked
Active
Viewed 1,016 times
0

Rafael Higa
- 655
- 1
- 8
- 17
1 Answers
1
If update has same columns. You can truncate table,
con.execute('TRUNCATE table RESTART IDENTITY;')
and then run pd.to_sql
with if_exists='append'

Alan Millirud
- 1,049
- 7
- 14