Commit 19d68d76 authored by ARCHER's avatar ARCHER

if_exists is replace, delete table instead drop (cascade pb)

parent 8458c87d
......@@ -139,9 +139,15 @@ def to_sql(df,*args,**kwargs):
tmp_table = None
new_table = False
if (kwargs['if_exists'] == 'append') and (table in metadata.tables):
if kwargs['if_exists'] == 'replace':
if table in metadata.tables :
# delete all rows in the table (not drop), then append, to prevent drop cascade
logger.info("deleting all rows in existing table %s" % table)
con.execute("delete from %s" % table)
# force append, because old table is empty
kwargs['if_exists'] = 'append'
elif (kwargs['if_exists'] == 'append') and (table in metadata.tables):
# will use a temporary table as a buffer ( for upsert copy )
logger.info("Temporary table used for fast update")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment