PostgreSQL partition (Reference)

Source: Internet
Author: User
Tags postgresql

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

    1. create table student_ Qualified  (Check  (Score >= 60  ))  inherits  (student)  ;
    2. 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.