I'm trying to delete some rows before inserting new data in my table (the past 30 days have to be updated daily to get accurate numbers).
I'm executing this:
from datetime import date, datetime, timedelta
import pandas as pd from sqlalchemy import create_engine
conn = create_engine("insert here string for connection")
conn.execution_options(autocommit = True)
start_date = datetime.strftime(date.today() - timedelta(days = 30),'%Y-%m-%d')
end_date = datetime.strftime(date.today(),'%Y-%m-%d')
delete_query = "delete from table where date between %s and %s" %(start_date,end_date)
pd.io.sql.execute(delete_query, conn)
Although I get no error, I can see in the database that the table is just always being duplicated. Any ideas?