Commit 68ae5585 authored by ARCHER's avatar ARCHER

2 methods for creating temporary tables

parent 7e02b7ce
......@@ -150,26 +150,27 @@ def to_sql(df,*args,**kwargs):
kwargs['if_exists'] = 'append'
if (kwargs['if_exists'] == 'append') and (table in metadata.tables):
# create a temporary table like destination table
tmp_table = "_%s" % table
con.execute("""
DROP TABLE IF EXISTS %s;
CREATE TEMP TABLE %s (
LIKE %s INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING INDEXES
) ;""" % (tmp_table, tmp_table, table))
tmp_table_orm = Table(tmp_table, metadata, autoload=True, autoload_with=con) # metadata.tables[tmp_table]
# will use a temporary table as a buffer ( for upsert copy )
#logger.info("Temporary table used for fast update")
#pandas_engine = pd.io.sql.pandasSQL_builder(con,meta=metadata)
#tmp_table = "_%s" % table
#if 'dtype' in kwargs:
# dtype=kwargs['dtype']
#else:
# dtype=None
#tmp_table_pd = TemporaryPandasTable("_%s" % table, pandas_engine, frame=df, if_exists="replace", dtype=dtype)
#tmp_table_pd.create()
temporary_method='PANDAS'
logger.info("Temporary table used for fast update with method %s" % temporary_method)
if temporary_method == 'LIKE':
# create a temporary table like destination table
tmp_table = "_%s" % table
con.execute("""
DROP TABLE IF EXISTS "%s";
CREATE TEMP TABLE "%s" (
LIKE "%s" INCLUDING CONSTRAINTS INCLUDING DEFAULTS INCLUDING INDEXES
) ;""" % (tmp_table, tmp_table, table))
tmp_table_orm = Table(tmp_table, metadata, autoload=True, autoload_with=con) # metadata.tables[tmp_table]
else:
#will use a temporary table as a buffer ( for upsert copy )
pandas_engine = pd.io.sql.pandasSQL_builder(con,meta=metadata)
tmp_table = "_%s" % table
if 'dtype' in kwargs:
dtype=kwargs['dtype']
else:
dtype=None
tmp_table_pd = TemporaryPandasTable("_%s" % table, pandas_engine, frame=df, if_exists="replace", dtype=dtype)
tmp_table_orm = tmp_table_pd.table
else:
new_table=True
......
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