dist_tbs=[r[0]forrinconn.execute(f"select logicalrelid::text from pg_dist_partition where logicalrelid::text in ('{export_tb_before}', '{export_master_tb}')").fetchall()]
# 跨年自动建当年母表:用上一年母表 like 出来(including all 带上索引/约束/默认值/注释),按 date_info 分区
# 跨年自动建当年母表:用上一年母表 like 出来(including all 带上索引/约束/默认值/注释),按 date_info 分区
# 不建的话跨年第一个月(如 2027-01)下面 like {export_master_tb} 会报表不存在
# 不建的话跨年第一个月(如 2027-01)下面 like {export_master_tb} 会报表不存在
# if not exists 幂等,已存在直接跳过、只加不删
# if not exists 幂等,已存在直接跳过、只加不删
# 保证幂等性,先删除原始表同周期的数据
sql=f"""
sql=f"""
create table if not exists {export_master_tb}
create table if not exists {export_master_tb}
(like {export_master_tb_before} including all)
(like {export_master_tb_before} including all)
partition by range (date_info);
partition by range (date_info);
drop table if exists {export_tb};
"""
create table if not exists {export_tb}
DBUtil.engine_exec_sql(engine,sql)
(
like {export_master_tb} including comments
# 新一年母表是 like 上一年建的,like 不带分布式属性;上一年已是分布式而本年不是时,把本年母表(刚建为空)转成分布式,否则数据又落回主节点
);
ifdb_type=='postgresql_cluster':
withengine.connect()asconn:
dist_tbs=[r[0]forrinconn.execute(f"select logicalrelid::text from pg_dist_partition where logicalrelid::text in ('{export_master_tb_before}', '{export_master_tb}')").fetchall()]
# 跨年自动建当年母表:用上一年母表 like 出来(including all 带上索引/约束/默认值/注释),按 date_info 分区
# 跨年自动建当年母表:用上一年母表 like 出来(including all 带上索引/约束/默认值/注释),按 date_info 分区
# 不建的话跨年第一个月(如 2027-01)下面 like {export_master_tb} 会报表不存在
# 不建的话跨年第一个月(如 2027-01)下面 like {export_master_tb} 会报表不存在
# if not exists 幂等,已存在直接跳过、只加不删
# if not exists 幂等,已存在直接跳过、只加不删
# 保证幂等性,先删除原始表同周期的数据
sql=f"""
sql=f"""
create table if not exists {export_master_tb}
create table if not exists {export_master_tb}
(like {export_master_tb_before} including all)
(like {export_master_tb_before} including all)
partition by range (date_info);
partition by range (date_info);
drop table if exists {export_tb};
"""
create table if not exists {export_tb}
DBUtil.engine_exec_sql(engine,sql)
(
like {export_master_tb} including comments
# 新一年母表是 like 上一年建的,like 不带分布式属性;上一年已是分布式而本年不是时,把本年母表(刚建为空)转成分布式,否则数据又落回主节点
);
ifdb_type=='postgresql_cluster':
withengine.connect()asconn:
dist_tbs=[r[0]forrinconn.execute(f"select logicalrelid::text from pg_dist_partition where logicalrelid::text in ('{export_master_tb_before}', '{export_master_tb}')").fetchall()]