postgrepSQL数据库创建二级分区表
数据库版本:version 10
以非继承的形式创建分区表,一级分区是城市,二级分区是天;指定分区有两种形式,RANGE和LIST,如果使用RANGE在创建分区语句中是通过FOR VALUES FROM...TO...;如果使用的是LIST,使用的是FOR VALUES IN (value值),多个value值的话以逗号隔开。
DROP TABLE measurement
//创建主表 CREATE TABLE measurement( p_day int not null, p_city varchar not null, peaktemp int, unitsales int ) PARTITION BY LIST (p_city); //创建一级分区表 CREATE TABLE measurement_c_beijing PARTITION OF measurement FOR VALUES IN ('beijing') PARTITION BY RANGE (p_day);
//创建二级分区表 CREATE TABLE measurement_c_beijing_20191101 PARTITION OF measurement_c_beijing FOR VALUES FROM (20191101) TO (20191102); //插入测试数据 insert into measurement values (20191101, 'beijing', 22,33);//成功 insert into measurement values (20191101, 'beijing', 23,35);//成功 insert into measurement values (20191102, 'beijing', 11,53);//失败,因为没有该分区 insert into measurement values (20191103, 'beijing', 03,53);//失败,同上 select * from measurement