zoukankan      html  css  js  c++  java
  • postgresql 分区表

    -- 分区表

    -- 创建主表
    CREATE TABLE measurement (
      city_id   int  not null,
      logdate   date not null,
      peaktemp  int,
      unitsales int
    )
    
      PARTITION BY RANGE (logdate);
    
    -- 创建子表
    CREATE TABLE measurement_2019_07
      PARTITION OF measurement
      FOR VALUES FROM ('2019-07-01') TO ('2019-07-31');
    
    -- insert data
    insert into measurement
    values (1, '2019-07-01', 1, 2);
    
    -- error 没有对应的子表
    insert into measurement
    values (1, '2019-08-01', 1, 2);
    
    CREATE TABLE measurement_2019_08
      PARTITION OF measurement
      FOR VALUES FROM ('2019-08-01') TO ('2019-08-30');
    
    -- ok 找到了对应的子表
    insert into measurement
    values (1, '2019-08-01', 1, 2);
    
    
    -- detach 子表
    ALTER TABLE measurement
      DETACH PARTITION measurement_2019_08;
    
    select *
    from measurement; -- 只能看到一条内容
    
    
    -- attach 子表
    ALTER TABLE measurement
      attach PARTITION measurement_2019_08 for VALUES FROM ('2019-08-01') TO ('2019-08-30');
    
    select *
    from measurement; -- 可以看到两条内容了
    
    
    -- detach
    ALTER TABLE measurement
      DETACH PARTITION measurement_2019_08;
    select *
    from measurement;
    -- 更新表字段
    alter table measurement
      add test char(200) default '';
    
    select *
    from measurement;
    select *
    from measurement_2019_07; -- attach 的表是 alert 成功的
    select *
    from measurement_2019_08; -- detach 的表示没有被 alert 的
    
    -- 将没有被 alert 的表 attach , 结果炸掉了 提示: child tables is missing column "test"
    ALTER TABLE measurement
      attach PARTITION measurement_2019_08 for VALUES FROM ('2019-08-01') TO ('2019-08-30');
    
  • 相关阅读:
    eclipse安装pydev
    pymongo常见的高级用法
    android sdk下载SDK Platform失败记录
    centos7 yum安装redis(转)
    centos7 将服务添加到systemctl
    python Parent.__init()和super(Child, self)的区别
    流畅的python第二十章属性描述符学习记录
    流畅的python第十九章元编程学习记录
    python 协程的学习记录
    [转]Shell脚本之无限循环的两种方法
  • 原文地址:https://www.cnblogs.com/twotigers/p/11226694.html
Copyright © 2011-2022 走看看