当前位置: 首页 > news >正文

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

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

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

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

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

http://www.lryc.cn/news/129491.html

相关文章:

  • EV PV AC SPI CPI TCPI
  • 【电商领域】Axure在线购物商城小程序原型图,品牌自营垂直电商APP原型
  • Cpp基础Ⅰ之编译、链接
  • 用户新增预测(Datawhale机器学习AI夏令营第三期)
  • RGOS日常管理操作
  • 阿里云使用WordPress搭建个人博客
  • 供应链安全和第三方风险管理:讨论如何应对供应链中的安全风险,以及评估和管理第三方合作伙伴可能带来的威胁
  • 《Java极简设计模式》第04章:建造者模式(Builder)
  • Go download
  • 2023年Java核心技术面试第四篇(篇篇万字精讲)
  • 数字化时代,数据仓库和商业智能BI系统演进的五个阶段
  • 【【Verilog典型电路设计之FIFO设计】】
  • JAVA设计模式总结之23种设计模式
  • Flutter 测试小结
  • docker build -t 和 docker build -f 区别
  • Java 项目日志实例基础:Log4j
  • K8S应用笔记 —— 签发自签名证书用于Ingress的https配置
  • webpack 和 ts 简单配置及使用
  • MATLAB算法实战应用案例精讲-【图像处理】交并比
  • [Machine Learning] decision tree 决策树
  • 【数学建模】-- 数学规划模型
  • SpringBoot使用RabbitMQ自动创建Exchange和Queue
  • 【设计模式】订单状态流传中的状态机与状态模式
  • 2.js中attr()用来修改或者添加属性或者属性值
  • 【虫洞攻击检测】使用多层神经网络的移动自组织网络中的虫洞攻击检测研究(Matlab代码实现)
  • 微分流形学习之一:基本定义
  • [C++]笔记-制作自己的静态库
  • 优酷视频码率、爱奇艺视频码率、B站视频码率、抖音视频码率对比
  • 用pytorch实现google net
  • 2023-8-15差分矩阵