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');
    
  • 相关阅读:
    ProtoType Design Tools
    什么是publickeytoken及publickeytoken的作用
    Windows最高权限system帐户
    Q70 AV01本本安装MAC
    解决MDict3在PPC下乱码的问题
    QT_XSP.CPP
    QT_XSP.CPP
    SetupFactory脚本
    DVD IFO FILE HEADER
    SerialPort comstat is being used without defining
  • 原文地址:https://www.cnblogs.com/twotigers/p/11226694.html
Copyright © 2011-2022 走看看