暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

openGauss每日一练第8天,分区表管理

原创 虫爷 2021-12-08
585

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;

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论