postgresql分区(引用)
Posted jinyuttt
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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) ;
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分区(引用)的主要内容,如果未能解决你的问题,请参考以下文章