create table test
(
id bigserial ,
create_time timestamp without time zone default now(),
description varchar
) PARTITION BY RANGE(create_time);
alter table test add CONSTRAINT pk_test primary key(id,create_time);
create table test_default partition of test default;
create table test_2019_12_25 partition of test for values from ('2019-12-25') to ('2019-12-25 24:00:00');
实验
添加数据
insert into TEST(DESCRIPTion) values('a'),('b');
insert into test (create_time, description) values('2019-12-25 12:12:00', 'c');
insert into test (create_time, description) values('2018-12-25 12:12:00', 'c');
查看数据
新建一个分表, 如果default 分表中有数据落在该分区,则该分表会创建失败
imos=# create table test_2018_12_25 partition of test for values from ('2018-12-25') to ('2018-12-25 24:00:00');
ERROR: updated partition constraint for default partition "test_default" would be violated by some row
imos=#