pg 建立分割槽表
1.建表
create table "exchange_detail"
("id" int8 primary key,
"exchange_type" int2,
"exchange_text" varchar(255)
,"detail_user" int8,
"create_time" timestamp(6));
comment on column "public"
."exchange_detail"
."id" is '置換記錄id'
;comment on column "public"
."exchange_detail"
."exchange_type" is '置換型別'
;comment on column "public"
."exchange_detail"
."exchange_text" is '置換描述'
;comment on column "public"
."exchange_detail"
."detail_user" is '置換使用者'
;comment on column "public"
."exchange_detail"
."create_time" is '建立時間'
;
2.建立分割槽表 直接繼承exchange_detail表就好了。一般的子表不需要加欄位。可以建立多個分割槽
create table exchange_detail01
(check (extract(month from create_time) = 1)
)inherits (exchange_detail)
;
2.1 給字表增加主鍵
alter table exchange_detail01 add primary key (id)
;
3.給子表建立索引 這個索引一般都是建立規則的字段
create index exchange_detail01_create_time on exchange_detail01(create_time)
;
4.建立觸發器函式
create or replace function exchange_detail_trigger(
) returns trigger as $$
beginif(
extract(month from new .create_time) = 1
) then
insert into exchange_detail01
values
(new .*)
;elseif
(extract(month from new .create_time) = 2
) then
insert into exchange_detail02
values
(new .*)
;elseif
(extract(month from new .create_time) = 3
) then
insert into exchange_detail03
values
(new .*)
;elseif
(extract(month from new .create_time) = 4
) then
insert into exchange_detail04
values
(new .*)
;elseif
(extract(month from new .create_time) = 5
)then
insert into exchange_detail05
values
(new .*)
;elseif
(extract(month from new .create_time) = 6
)then
insert into exchange_detail06
values
(new .*)
;elseif
(extract(month from new .create_time) = 7
)then
insert into exchange_detail07
values
(new .*)
;elseif
(extract(month from new .create_time) = 8
)then
insert into exchange_detail08
values
(new .*)
;elseif
(extract(month from new .create_time) = 9
)then
insert into exchange_detail09
values
(new .*)
;elseif
(extract(month from new .create_time) = 10
)then
insert into exchange_detail10
values
(new .*)
;elseif
(extract(month from new .create_time) = 11
)then
insert into exchange_detail11
values
(new .*)
;elseif
(extract(month from new .create_time) = 12
)then
insert into exchange_detail12
values
(new .*)
;else
raise exception 'date out of range!'
;endif;
return null ;
end; $$ language plpgsql;
5.建立觸發器
create trigger exchange_detail_trigger before insert on exchange_detail
for each row
execute procedure exchange_detail_trigger(
);
Oracle 建立分割槽表
建立表空間 create tablespace mytablespace 1 datafile c oracle product 10.1.0 oradata mydata mytablespace1.dbf size 100m extent management local uniform siz...
hive 建立分割槽表
必須在表定義時建立partition a 單分割槽建表語句 create table day table id int,content string partitioned by dt string 單分割槽表,按天分割槽,在表結構中存在id,content,dt三列。以dt為資料夾區分 b 雙分割...
Oracle 建立分割槽表
建立表空間 create tablespace mytablespace 1 datafile c oracle product 10.1.0 oradata mydata mytablespace1.dbf size 100m extent management local uniform siz...