Postgresql Partition Table One

Source: Internet
Author: User
Tags postgresql recode

Postgres 10 new Feature partition table

http://francs3.blog.163.com/blog/static/40576727201742103158135/

Postgres 10 before partition table plug-in implementation Pg_pathman

Https://yq.aliyun.com/articles/62314#25

Here simple records are based on triggers or rule implementations

Create a partitioned table
CREATE table RECORD (--Main Table
record_id int not NULL,
Record_pro Text Not NULL,
city_id int,
City_name text
);

CREATE TABLE Record_defalut (CHECK (city_id = 0)) INHERITS (RECORD); --default
CREATE TABLE record_bj (CHECK (city_id = 1)) INHERITS (RECORD); --Beijing
CREATE TABLE record_sh (CHECK (city_id = 2)) INHERITS (RECORD); --Shanghai
CREATE TABLE Record_gz (CHECK (city_id = 3)) INHERITS (RECORD); --Guangzhou
CREATE TABLE RECORD_SZ (CHECK (city_id = 4)) INHERITS (RECORD); --Shenzhen

Create a rule

CREATE RULE Record_default_rule_insert as
On INSERT to RECORD WHERE city_id = 0
Do INSTEAD
INSERT into Record_defalut VALUES (new.*);

CREATE RULE Record_bj_rule_insert as
On INSERT to RECORD WHERE city_id = 1
Do INSTEAD
INSERT into RECORD_BJ VALUES (new.*);

CREATE RULE Record_sh_rule_insert as
On INSERT to RECORD WHERE city_id = 2
Do INSTEAD
INSERT into Record_sh VALUES (new.*);

CREATE RULE Record_gz_rule_insert as
On INSERT to RECORD WHERE city_id = 3
Do INSTEAD
INSERT into Record_gz VALUES (new.*);

CREATE RULE Record_sz_rule_insert as
On INSERT to RECORD WHERE city_id = 4
Do INSTEAD
INSERT into RECORD_SZ VALUES (new.*);

Input analog data

Truncate RECORD;

INSERT into RECORD
SELECT generate_series (1, +), ' Recode ', (Int4 (random () *10))%5, ' City ';

INSERT into RECORD VALUES (1, ' Recode ', 3, ' City ');
INSERT into RECORD VALUES (2, ' Recode ', 3, ' City ');
INSERT into RECORD VALUES (3, ' Recode ', 0, ' city ');
INSERT into RECORD VALUES (4, ' Recode ', 0, ' city ');
INSERT into RECORD VALUES (5, ' Recode ', 4, ' City ');
INSERT into RECORD VALUES (6, ' Recode ', 3, ' City ');
INSERT into RECORD VALUES (7, ' Recode ', 3, ' City ');
INSERT into RECORD VALUES (8, ' Recode ', 0, ' city ');
INSERT into RECORD VALUES (9, ' Recode ', 0, ' city ');
INSERT into RECORD VALUES ("Recode", 2, ' City ');

Postgresql Partition Table One

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.