openGauss每日一练第8天课后作业
1.创建一个含有5个分区的范围分区表store,在每个分区中插入记录
create table store (
prod_id int not null,
price numeric(10,2),
amount int)
partition by range (prod_id)
( partition store_p1 values less than (1000),
partition store_p2 values less than (2000),
partition store_p3 values less than (3000),
partition store_p4 values less than (4000),
partition store_p5 values less than (5000));
\d+ store
select * from pg_partition;
insert into store values
(56,1300.99,15),
(1201,98.88,12),
(2340,9.99,34),
(4928,5.36,6),
(3870,6431.99,3);
2.查看分区1上的数据
select * from store partition(store_p1);
3.重命名分区2
alter table store rename partition store_p2 to store_p2_1;
select * from store partition(store_p2_1);
4.删除分区5
alter table store drop partition store_p5;
select * from pg_partition;
5.增加分区6
alter table store add partition store_p6 values less than (6000);
insert into store values (4239,2.99,10);
select * from store partition(store_p6);
--由于store_p5分区被删了,新插入的数据落在了store_p6
6.在系统表pg_partition中查看分区信息
select * from pg_partition;
7.删除分区表
drop table store;