標籤:trigger font plpgsql 觸發器 hit isp instead webkit int
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
>= 60) THEN
INSERT
INTO student_qualified VALUES (NEW.*);
ELSE
INSERT
INTO student_nqualified VALUES (NEW.*);
END
IF;
RETURN
NULL;
END;
$$
LANGUAGE plpgsql ;
//建立觸發器
REATE TRIGGER insert_student
BEFORE INSERT ON student
FOR EACH row
EXECUTE PROCEDURE student_insert_trigger() ;
postgresql分區(引用)