1.首先準備測試的父表:
2.建立子表:
create table info_2017(
check ( year = '2017' )
) inherits (info);
create table info_2018(
check ( year = '2018' )
) inherits (info);
3.建立各表索引
create index info_2017_index on info_2017(year);
create index info_2018_index on info_2018(year);
4.建立觸發器函式
create or replace function info_trigger()
returns trigger as $$
begin
if ( new.year = '2017') then
insert into info_2017 values (new.*);
elsif ( new.year = '2018' ) then
insert into info_2018 values (new.*);
else
raise exception 'date out of range. fix the tbl_partition_insert_trigger() function!';
end if;
return null;
end;
$$
language plpgsql;
create trigger my_info_trigger
before insert on info
for each row execute procedure info_trigger();
完成後的結果會根據插入語句的year欄位插入到分表,主表也會同時插入.據說會對效能有提公升,還未測試; postgresql 觸發器寫法
create or replace function delete fdr returns trigger as delete fdr begin delete from object classes where object classes dataroom id old dataroom id ...
Postgresql 函式 觸發器寫法
1 資料庫環境 table 學生分數表 create table stu score stuno serial not null,學生編號 major character varying 16 專業課程 score integer 分數 with oids false alter table stu...
postgresql 觸發器 觸發函式 動態建表
postgresql 建立分割槽表,sql優化之postgresql table partitioning postgresql中使用動態sql 實現自動按時間建立表分割槽 declare createon varchar 32 createyy varchar 4 tablename varcha...