GBase8c 自动分区例子
DROP TABLE IF EXISTS t_auto_create_partition;
CREATE TABLE t_auto_create_partition (
r_id character varying(32) NOT NULL,
s_id character varying(200),
r_ratio character varying(100),
create_time timestamp(0) without time zone DEFAULT LOCALTIMESTAMP NOT NULL
) PARTITION BY RANGE ("create_time") INTERVAL ('1 month')
(
PARTITION p1 VALUES LESS THAN('2020-01-01 00:00:00')
);
INSERT INTO t_auto_create_partition (r_id, s_id, r_ratio, create_time)
VALUES
('1', 's1', 'ratio1', '2020-01-01 10:00:00'),
('2', 's2', 'ratio2', '2021-02-01 10:00:00'),
('22', 's22', 'ratio2', '2021-02-03 10:00:00'),
('3', 's3', 'ratio3', '2022-03-01 10:00:00'),
('4', 's4', 'ratio4', '2023-04-01 10:00:00'),
('5', 's5', 'ratio5', '2024-05-01 10:00:00'),
('6', 's6', 'ratio6', '2025-06-01 10:00:00'),
('7', 's7', 'ratio7', '2020-03-06 10:00:00'),
('8', 's8', 'ratio8', '2019-07-04 10:00:00')
;
select * from t_auto_create_partition partition(p1);
select * from t_auto_create_partition partition(sys_p7);
select * from pg_partition where parentid = (select parentid from pg_partition where relname = 't_auto_create_partition' and parttype = 'r');
