首页 > 代码库 > postgresql分区(引用)
postgresql分区(引用)
1 建立大表。
2 创建分区继承
3 定义Rule或者Trigger?
1 建立大表
CREATE TABLE student (student_id bigserial, name varchar(32), score smallint)
2 创建分区继承
- CREATE TABLE student_qualified (CHECK (score >= 60 )) INHERITS (student) ;
- CREATE TABLE student_nqualified (CHECK (score < 60)) INHERITS (student) ;
3 定义Rule或者Trigger。
(1)创建rule
CREATE OR REPLACE RULE insert_student_qualified
AS ON INSERT TO student
WHERE score >= 60
DO INSTEAD
INSERT INTO student_qualified VALUES(NEW.*);
CREATE OR REPLACE RULE insert_student_nqualified
AS ON INSERT TO student
WHERE score < 60
DO INSTEAD
INSERT INTO student_nqualified VALUES(NEW.*);
(2)创建方法及触发器
REATE OR REPLACE FUNCTION student_insert_trigger()
RETURNS TRIGGER AS
$$
- BEGIN
- IF(NEW.score
- INSERT
- ELSE
- INSERT
- END
- RETURN
- END;
$$
LANGUAGE plpgsql ;
//创建触发器
REATE TRIGGER insert_student
BEFORE INSERT ON student
FOR EACH row
EXECUTE PROCEDURE student_insert_trigger() ;
postgresql分区(引用)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。