[CG] : add arg dtype to update_to_sql

This commit is contained in:
Colas Geier 2023-07-04 14:24:18 +02:00
parent 0d2b1fa9c6
commit 879ae10150

View File

@ -223,7 +223,7 @@ def update_ref(file, table, schema=None, update=False):
update_ref_table(file, table, schema, update) update_ref_table(file, table, schema, update)
def update_to_sql(df, con, table_name, schema_name, key_name, checkid=True): def update_to_sql(df, con, table_name, schema_name, key_name, checkid=True, dtype=None):
from sys import exit from sys import exit
a = [] a = []
@ -254,9 +254,9 @@ def update_to_sql(df, con, table_name, schema_name, key_name, checkid=True):
if col in primary_key: if col in primary_key:
b.append("t.{col}=f.{col}".format(col=col)) b.append("t.{col}=f.{col}".format(col=col))
else: else:
dtype = type_cols[col] dtyp = type_cols[col]
if hasattr(dtype,'enums') : if hasattr(dtyp,'enums') :
dty = '.'.join([dtype.schema,dtype.name]) dty = '.'.join([dtyp.schema,dtyp.name])
a.append("{col}=t.{col}::{typ}".format(col=col,typ=dty)) a.append("{col}=t.{col}::{typ}".format(col=col,typ=dty))
else: else:
a.append("{col}=t.{col}".format(col=col)) a.append("{col}=t.{col}".format(col=col))
@ -266,7 +266,8 @@ def update_to_sql(df, con, table_name, schema_name, key_name, checkid=True):
name = 'temp_table', name = 'temp_table',
con = con, con = con,
schema = schema, schema = schema,
if_exists = 'replace' if_exists = 'replace',
dtype = dtype
# geom_col = df.geometry.name # geom_col = df.geometry.name
) )
else: else:
@ -276,7 +277,8 @@ def update_to_sql(df, con, table_name, schema_name, key_name, checkid=True):
schema = schema, schema = schema,
if_exists = 'replace', if_exists = 'replace',
index = False, index = False,
method = 'multi' method = 'multi',
dtype = dtype
) )
update_stmt_1 = "UPDATE {sch}.{final_table} f".format(sch=schema,final_table=table) update_stmt_1 = "UPDATE {sch}.{final_table} f".format(sch=schema,final_table=table)