-- 创建表 根据ds分表(ds为yyyyMMdd格式)createtable test
(
id bigintNOTNULLDEFAULT nextval('test_id_seq'::regclass),
ip text,
name text,
create_time timestampwithtime zone NOTNULL,
ds bigint)PARTITIONBY LIST (ds);-- 创建注释COMMENTONTABLE test IS'分区表测试';COMMENTONCOLUMN test.ip IS'访问ip';COMMENTONCOLUMN test.name IS'名称';COMMENTONCOLUMN test.create_time IS'创建时间';
3)创建分区表子表
-- 创建分区子表-- create table %s_%s partition of %s for values in (%s)createtable test_20200924 partitionof test forvaluesin(20200924);
select name,to_char(create_time,'yyyymmddhh24mi')as period from test where ds in(20200921,20200922,20200923,20200924)and create_time <='2020-09-24 15:30:00.000'and create_time >='2020-09-21 00:00:00.000'groupby name,to_char(create_time,'yyyymmddhh24mi')orderby name,period