Greenplum多级分区表添加分区报错ERROR: no partitions specified at depth 2

一般来说,我们二级分区表都会使用模版,如果没有使用模版特性,那么就会报ERROR: no partitions specified at depth 2类似的错误。因为没有模版,必须要显式指定分区。

当然我们在建表的时候,如果没有指定,那么后面也可以通过alter table 语句进行添加。下面我们通过一个例子看一下。

sql 复制代码
CREATE TABLE sales (
    trans_id integer,
    ctime timestamp without time zone,
    region text
)
 DISTRIBUTED BY (trans_id) PARTITION BY RANGE(ctime)
          SUBPARTITION BY LIST(region)
          (
          START ('2023-08-18 00:00:00'::timestamp without time zone) END ('2023-08-19 00:00:00'::timestamp without time zone) WITH (tablename='sales_1_prt_1', appendonly='false')
                  (
                  SUBPARTITION usa VALUES('usa') WITH (tablename='sales_1_prt_1_2_prt_usa', appendonly='false'),
                  SUBPARTITION asia VALUES('asia') WITH (tablename='sales_1_prt_1_2_prt_asia', appendonly='false'),
                  SUBPARTITION europe VALUES('europe') WITH (tablename='sales_1_prt_1_2_prt_europe', appendonly='false')
                  )
          );

#如果只指定一级分区,添加分区会报错
alter table sales add partition sale_3  start (date '2023-08-20') inclusive end (date '2023-08-21') exclusive ;
NOTICE:  CREATE TABLE will create partition "sales_1_prt_sale_3" for table "sales"
ERROR:  no partitions specified at depth 2
#必须显式指定才可以添加成功
alter table sales add partition sale_2 
START ('2023-08-19 00:00:00'::timestamp without time zone) END ('2023-08-20 00:00:00'::timestamp without time zone) 
             (
                  SUBPARTITION usa VALUES('usa'),
                  SUBPARTITION asia VALUES('asia') ,
                  SUBPARTITION europe VALUES('europe') 
                );
#插入一些测试数据
insert into sales select generate_series(1,10000000) ,current_date ,'usa';
insert into sales select generate_series(1,10000000) ,current_date ,'asia';
insert into sales select generate_series(1,10000000) ,current_date ,'europe';

#添加模版,就算之前有历史数据,也是瞬间完成
ALTER TABLE sales
SET SUBPARTITION TEMPLATE
          (
          SUBPARTITION usa VALUES('usa') WITH (tablename='sales'),
          SUBPARTITION asia VALUES('asia') WITH (tablename='sales'),
          SUBPARTITION europe VALUES('europe') WITH (tablename='sales')
          )
;
NOTICE:  adding level 1 subpartition template specification for relation "sales"
NOTICE:  CREATE TABLE will create partition "sales_1_prt_subpartition_template" for table "sales"NOTICE:  CREATE TABLE will create partition "sales" for table "sales_1_prt_subpartition_template"
NOTICE:  CREATE TABLE will create partition "sales" for table "sales_1_prt_subpartition_template"
NOTICE:  CREATE TABLE will create partition "sales" for table "sales_1_prt_subpartition_template"
ALTER TABLE

#这次只指定一级分区就可以添加成功
alter table sales  add partition sale_3  start (date '2023-08-20') inclusive end (date '2023-08-21') exclusive ;
NOTICE:  CREATE TABLE will create partition "sales_1_prt_sale_2" for table "sales"
NOTICE:  CREATE TABLE will create partition "sales_1_prt_sale_2_2_prt_usa" for table "sales_1_prt_sale_2"
NOTICE:  CREATE TABLE will create partition "sales_1_prt_sale_2_2_prt_asia" for table "sales_1_prt_sale_2"
NOTICE:  CREATE TABLE will create partition "sales_1_prt_sale_2_2_prt_europe" for table "sales_1_prt_sale_2"
ALTER TABLE

总结:

建表的时候,最好添加二级分区以后的模版,模版也可以后面变更,如果不加模版,添加分区的时候,必须指定子分区,所以分区级别越多,越复杂。

相关推荐
FII工业富联科技服务40 分钟前
Omniverse + Isaac Teleop + 合成数据:工业富联机器人大脑训练+执行落地闭环拆解
大数据·人工智能·深度学习·机器学习·机器人·制造·具身智能
airank3 小时前
2026年GEO服务商选型指南:系统梳理服务商分类框架、主流服务商能力横评、企业级选型六大维度及避坑要点,帮助企业在AI搜索时代做出科学决策。
大数据·人工智能·数据分析·aigc
Delite8023 小时前
摆脱实验室束缚:便携式卡尔费休微量水分检测技术与现场应用解析
大数据·网络·人工智能
袋鼠云数栈3 小时前
实时湖仓如何真正做到“数据够新”?
大数据·数据库·人工智能·数据治理
ACP广源盛139246256733 小时前
M6/M5 Pro Mac mini 端侧 AI 落地@ACP#YLB3116 中端多盘存储扩展在 AI 服务中的机会与应用场景
大数据·网络·数据库·人工智能·嵌入式硬件·macos
大大大大晴天4 小时前
大数据数据治理到底治理什么:从“数据可用”到“数据可信”
大数据
ACP广源盛139246256734 小时前
M6/M5 Pro Mac mini 端侧 AI 新形态@ACP#GSV5800 Serdes 长距离视频传输在 AI 服务中的机会与落地场景
大数据·网络·数据库·人工智能·嵌入式硬件·macos·音视频
策案案案5 小时前
YOLO: 将AI Agents嵌入到IntelliJ IDEA
java·大数据·人工智能·笔记·yolo·microsoft·intellij-idea
倔强的石头_5 小时前
事务边界与批量写入:避免长事务、锁等待和日志压力
数据库
努力努力再努力wz6 小时前
【Redis入门系列】从 KEYS 到 SCAN:渐进式遍历、Cursor 与位反转原理
数据库·redis·缓存