PostgreSQL的分区表建立(3)
来源:未知 责任编辑:责任编辑 发表时间:2014-01-25 11:38 点击:次
ELSIF ( NEW.create_time >= DATE '2012-08-01' AND
NEW.create_time < DATE '2012-09-01' ) THEN
INSERT INTO test.parent_table_2012_08 VALUES (NEW.id,NEW.name,NEW.create_time);
ELSIF ( NEW.create_time >= DATE '2012-09-01' AND
NEW.create_time < DATE '2012-10-01' ) THEN
INSERT INTO test.parent_table_2012_09 VALUES (NEW.id,NEW.name,NEW.create_time);
ELSIF ( NEW.create_time >= DATE '2012-10-01' AND
NEW.create_time < DATE '2012-11-01' ) THEN
INSERT INTO test.parent_table_2012_10 VALUES (NEW.id,NEW.name,NEW.create_time);
ELSIF ( NEW.create_time >= DATE '2012-11-01' AND
NEW.create_time < DATE '2012-12-01' ) THEN
INSERT INTO test.parent_table_2012_11 VALUES (NEW.id,NEW.name,NEW.create_time); www.2cto.com
ELSIF ( NEW.create_time >= DATE '2012-12-01' AND
NEW.create_time < DATE '2013-01-01' ) THEN
INSERT INTO test.parent_table_2012_12 VALUES (NEW.id,NEW.name,NEW.create_time);
ELSE
RAISE EXCEPTION 'Date out of range.Fix the test.parent_table_insert_trigger() function!';
END IF;
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
4.创建触发器
CREATE TRIGGER tri_insert_parent_table
BEFORE INSERT ON test.parent_table
FOR EACH ROW EXECUTE PROCEDURE test.tri_parent_tab_insert();
5.测试
至此就OK了。前端插入时只要插入主表就可以自动将数据按时间分类分插到子表里去。
插入一定的测试数据,来看看效果
kenyon=# select count(1) from test.parent_table_2012_03;
www.2cto.com
count
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>