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');
    
  • 相关阅读:
    Ubuntu Linux下的Wireshark使用drcom_2011.lua分析drcom协议
    Keil提示premature end of file错误 无法生成HEX文件
    Linux和win7(win10)双系统时间错误问题 时间相差8小时
    Wireshark使用drcom_2011.lua插件协助分析drcom协议
    Keil报错failed to execute 'd:KeilC51BINC51.EXE'
    第一篇博文
    LG 7078 贪吃蛇
    LG 1791 人员雇佣
    洛谷 2698 Flowerpot
    HDU 5965 扫雷
  • 原文地址:https://www.cnblogs.com/twotigers/p/11226694.html
Copyright © 2011-2022 走看看