Commit a8571acd by hejiangming

年度搜索词增加创表判断

parent e9f81eb6
...@@ -36,6 +36,17 @@ if __name__ == '__main__': ...@@ -36,6 +36,17 @@ if __name__ == '__main__':
export_tb_rel = f"{export_tb_before}_copy" export_tb_rel = f"{export_tb_before}_copy"
engine = DBUtil.get_db_engine(db_type, site_name) engine = DBUtil.get_db_engine(db_type, site_name)
# 年表每年一张:当年正式表不存在时(新一年首次导出),按上一年年表结构新建
if date_type == DateTypes.year.name:
last_year_tb = f"{site_name}_aba_last_year_{int(year) - 1}"
with engine.connect() as connection:
exist = connection.execute(f"select to_regclass('{export_tb_before}')").scalar()
if exist is None:
sql = f"create table {export_tb_before} (like {last_year_tb} including all);"
print("================================当年年表不存在,复制上一年表结构================================")
print(sql)
connection.execute(sql)
# 创建备份表 # 创建备份表
with engine.connect() as connection: with engine.connect() as connection:
sql = f""" sql = f"""
......
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