UPDATE clean zh
This commit is contained in:
parent
991286e4df
commit
9716e61ea4
42
pycen/zh.py
42
pycen/zh.py
@ -638,7 +638,8 @@ class ref_hydro:
|
|||||||
#####################################
|
#####################################
|
||||||
### Update ###
|
### Update ###
|
||||||
#####################################
|
#####################################
|
||||||
def update_to_sql(df, con, table_name, schema_name, key_name):
|
def update_to_sql(df,con,table_name,schema_name,key_name,geom_col='geom'):
|
||||||
|
from geopandas import GeoDataFrame
|
||||||
a = []
|
a = []
|
||||||
b = []
|
b = []
|
||||||
table = table_name
|
table = table_name
|
||||||
@ -650,14 +651,24 @@ def update_to_sql(df, con, table_name, schema_name, key_name):
|
|||||||
b.append("t.{col}=f.{col}".format(col=col))
|
b.append("t.{col}=f.{col}".format(col=col))
|
||||||
else:
|
else:
|
||||||
a.append("{col}=t.{col}".format(col=col))
|
a.append("{col}=t.{col}".format(col=col))
|
||||||
df.to_sql(
|
if isinstance(df,GeoDataFrame):
|
||||||
name = 'temp_table',
|
df.to_postgis(
|
||||||
con = con,
|
name = 'temp_table',
|
||||||
schema = schema,
|
con = con,
|
||||||
if_exists = 'replace',
|
schema = schema,
|
||||||
index = False,
|
if_exists = 'replace',
|
||||||
method = 'multi'
|
index = False,
|
||||||
)
|
geom_col=geom_col,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
df.to_sql(
|
||||||
|
name = 'temp_table',
|
||||||
|
con = con,
|
||||||
|
schema = schema,
|
||||||
|
if_exists = 'replace',
|
||||||
|
index = False,
|
||||||
|
method = 'multi'
|
||||||
|
)
|
||||||
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)
|
||||||
update_stmt_2 = " FROM {sch}.temp_table t".format(sch=schema)
|
update_stmt_2 = " FROM {sch}.temp_table t".format(sch=schema)
|
||||||
update_stmt_6 = " WHERE %s"%' AND '.join(b)
|
update_stmt_6 = " WHERE %s"%' AND '.join(b)
|
||||||
@ -671,16 +682,3 @@ def update_to_sql(df, con, table_name, schema_name, key_name):
|
|||||||
return print('END update')
|
return print('END update')
|
||||||
|
|
||||||
|
|
||||||
# [SQL: INSERT INTO zones_humides.r_site_reghydro (id, id_geom_site, id_reg_hydro, id_permanence, rmq_toponymie, in_out)
|
|
||||||
# VALUES (%(id)s, %(id_geom_site)s, %(id_reg_hydro)s, %(id_permanence)s, %(rmq_toponymie)s, %(in_out)s)]
|
|
||||||
# [parameters: ({'id': 0, 'id_geom_site': 5, 'id_reg_hydro': '0', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': True},
|
|
||||||
# {'id': 1, 'id_geom_site': 5, 'id_reg_hydro': '1', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': False},
|
|
||||||
# {'id': 2, 'id_geom_site': 6, 'id_reg_hydro': '0', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': True},
|
|
||||||
# {'id': 3, 'id_geom_site': 6, 'id_reg_hydro': '1', 'id_permanence': '1', 'rmq_toponymie': '', 'in_out': False},
|
|
||||||
# {'id': 4, 'id_geom_site': 7, 'id_reg_hydro': '2', 'id_permanence': '2', 'rmq_toponymie': 'plusieurs petites sources dans versant', 'in_out': True},
|
|
||||||
# {'id': 5, 'id_geom_site': 7, 'id_reg_hydro': '1', 'id_permanence': '2', 'rmq_toponymie': 'longe la route D209a', 'in_out': False},
|
|
||||||
# {'id': 6, 'id_geom_site': 8, 'id_reg_hydro': '0', 'id_permanence': '2', 'rmq_toponymie': '', 'in_out': True},
|
|
||||||
# {'id': 7, 'id_geom_site': 8, 'id_reg_hydro': '3', 'id_permanence': None, 'rmq_toponymie': '', 'in_out': False}
|
|
||||||
# ... displaying 10 of 5779 total bound parameter sets ...
|
|
||||||
# {'id': 5777, 'id_geom_site': 1951, 'id_reg_hydro': '0', 'id_permanence': None, 'rmq_toponymie': '', 'in_out': True},
|
|
||||||
# {'id': 5778, 'id_geom_site': 1951, 'id_reg_hydro': '3', 'id_permanence': None, 'rmq_toponymie': '', 'in_out': False})]
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user