Postgresql 分區表 一

來源:互聯網
上載者:User

標籤:and   http   postgre   特性   res   pos   path   check   creat   

Postgres 10 新特性 分區表

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

Postgres 10 之前分區表外掛程式實現 pg_pathman

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

 

這裡簡單記錄基於觸發器或規則實現

 

建立分區表
CREATE TABLE RECORD ( --主表
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); --北京
CREATE TABLE RECORD_SH (CHECK(city_id = 2)) INHERITS (RECORD); --上海
CREATE TABLE RECORD_GZ (CHECK(city_id = 3)) INHERITS (RECORD); --廣州
CREATE TABLE RECORD_SZ (CHECK(city_id = 4)) INHERITS (RECORD); --深圳

建立規則

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.*);

輸入類比資料

truncate RECORD;

INSERT INTO RECORD
SELECT generate_series(1, 100),‘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(10 , ‘recode‘, 2, ‘city‘);

 

Postgresql 分區表 一

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.