1 build Large tables.
2 Creating partition Inheritance
3 define rule or trigger?
1 Building Large Tables
CREATE table student (student_id bigserial, name varchar (+), score smallint)
2 create partition Inheritance
- create table student_ Qualified (Check (Score >= 60 )) inherits (student) ;
- CREATE TABLE student_nqualified (CHECK (score <) ) INHERITS (student) ;
3 defining rule or trigger (1) Create Rule
create or replace RULE Insert_student_ Qualified&NBSP;
as on insert to student &NBSP;
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) Creating methods and triggers
reate OR REPLACE FUNCTION Student_insert_trigger ()
RETURNS TRIGGER as
$$
BEGIN
IF (new.score
>= ) Then
INSERT
into student_qualified VALUES (new.*);
ELSE
INSERT
into student_nqualified VALUES (new.*);
END
IF;
RETURN
NULL;
END;
$$
LANGUAGE Plpgsql ;
Create a Trigger
reate TRIGGER insert_student
Before INSERT on student
For each row
EXECUTE PROCEDURE Student_insert_trigger () ;
PostgreSQL partition (Reference)