#openGauss #入门 #安装 #数据库 #开源
知识来源:docs-opengauss.osinfra.cn/zh/
创建START END范围分区表示例
示例3:以“START(partition_value) END (partition_value | MAXVALUE)”方式创建START END范围分区表graderecord。含有3个分区,分区键为INTEGER类型。分区的范围分别为:0<= grade<60,60<= grade<90,90<=grade< MAXVALUE。
--创建分区表graderecord。
openGauss=# CREATE TABLE graderecord
(
number INTEGER,
name CHAR(20),
class CHAR(20),
grade INTEGER
)
PARTITION BY RANGE(grade)
(
PARTITION pass START(60) END(90),
PARTITION excellent START(90) END(MAXVALUE)
);
-- 数据插入分区。
openGauss=# insert into graderecord values('210101','Alan','21.01',92);
openGauss=# insert into graderecord values('210102','Ben','21.01',62);
openGauss=# insert into graderecord values('210103','Brain','21.01',26);
openGauss=# insert into graderecord values('210204','Carl','21.02',77);
openGauss=# insert into graderecord values('210205','David','21.02',47);
openGauss=# insert into graderecord values('210206','Eric','21.02',97);
openGauss=# insert into graderecord values('210307','Frank','21.03',90);
openGauss=# insert into graderecord values('210308','Gavin','21.03',100);
openGauss=# insert into graderecord values('210309','Henry','21.03',67);
openGauss=# insert into graderecord values('210410','Jack','21.04',75);
openGauss=# insert into graderecord values('210311','Jerry','21.04',60);
--查询graderecord的数据。
openGauss=# SELECT * FROM graderecord;
number | name | class | grade
--------+----------------------+----------------------+-------
210103 | Brain | 21.01 | 26
210205 | David | 21.02 | 47
210102 | Ben | 21.01 | 62
210204 | Carl | 21.02 | 77
210309 | Henry | 21.03 | 67
210410 | Jack | 21.04 | 75
210311 | Jerry | 21.04 | 60
210101 | Alan | 21.01 | 92
210206 | Eric | 21.02 | 97
210307 | Frank | 21.03 | 90
210308 | Gavin | 21.03 | 100
(11 rows)
--查询graderecord的pass分区数据。
openGauss=# SELECT * FROM graderecord PARTITION (pass);
ERROR: partition "pass" of relation "graderecord" does not exist
查询失败。
原因是“PARTITION pass START(60) END(90),”是第一个分区定义,且该定义有START值,则范围(MINVALUE, 60)将自动作为第一个实际分区,其名称为“pass_0”。
而该定义语义描述的“60<= grade<90”分区的名称为“pass_1”。
--查询graderecord的pass_0分区数据。
openGauss=# SELECT * FROM graderecord PARTITION (pass_0);
number | name | class | grade
--------+----------------------+----------------------+-------
210103 | Brain | 21.01 | 26
210205 | David | 21.02 | 47
(2 rows)
--查询graderecord的pass_1分区数据。
openGauss=# SELECT * FROM graderecord PARTITION (pass_1);
number | name | class | grade
--------+----------------------+----------------------+-------
210102 | Ben | 21.01 | 62
210204 | Carl | 21.02 | 77
210309 | Henry | 21.03 | 67
210410 | Jack | 21.04 | 75
210311 | Jerry | 21.04 | 60
(5 rows)
--查询graderecord的excellent分区数据。
openGauss=# SELECT * FROM graderecord PARTITION (excellent);
number | name | class | grade
--------+----------------------+----------------------+-------
210101 | Alan | 21.01 | 92
210206 | Eric | 21.02 | 97
210307 | Frank | 21.03 | 90
210308 | Gavin | 21.03 | 100
(4 rows)
#openGauss #入门 #安装 #数据库 #开源