数据仓库服务 GAUSSDB(DWS)-CREATE FOREIGN TABLE (SQL on OBS or Hadoop):示例3

时间:2024-10-21 16:50:37

示例3

关于包含信息约束(Informational Constraint)HDFS外表的相关操作。

  • 创建含有信息约束(Informational Constraint)的HDFS外表。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    CREATE FOREIGN TABLE ft_region  (
     R_REGIONKEY  int,
     R_NAME TEXT,
     R_COMMENT TEXT
      , primary key (R_REGIONKEY) not enforced)
    SERVER hdfs_server
    OPTIONS(format 'orc',
        encoding 'utf8',
     foldername '/user/hive/warehouse/mppdb.db/region_orc11_64stripe')
    DISTRIBUTE BY roundrobin;
    
  • 查看region表是否有信息约束索引:
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    SELECT relname,relhasindex FROM pg_class WHERE oid='ft_region'::regclass;
            relname         | relhasindex 
    ------------------------+-------------
            ft_region       | f
    (1 row)
    
    SELECT conname, contype, consoft, conopt, conindid, conkey FROM pg_constraint WHERE conname ='ft_region_pkey';
       conname      | contype | consoft | conopt | conindid | conkey
    ----------------+---------+---------+--------+----------+--------
     ft_region_pkey | p       | t       | t      |        0 | {1}
    (1 row)
    
  • 删除信息约束:
    1
    2
    3
    4
    5
    6
    ALTER FOREIGN TABLE ft_region DROP CONSTRAINT ft_region_pkey RESTRICT;
    
    SELECT conname, contype, consoft, conindid, conkey FROM pg_constraint WHERE conname ='ft_region_pkey';
     conname | contype | consoft | conindid | conkey 
    ---------+---------+---------+----------+--------
    (0 rows)
    
  • 添加一个唯一信息约束:
    1
    ALTER FOREIGN TABLE ft_region ADD CONSTRAINT constr_unique UNIQUE(R_REGIONKEY) NOT ENFORCED;
    
    删除唯一信息约束:
    1
    2
    3
    4
    5
    6
    ALTER FOREIGN TABLE ft_region DROP CONSTRAINT constr_unique RESTRICT;
    
    SELECT conname, contype, consoft, conindid, conkey FROM pg_constraint WHERE conname ='constr_unique';
     conname | contype | consoft | conindid | conkey 
    ---------+---------+---------+----------+--------
    (0 rows)
    
  • 添加一个唯一信息约束:
    1
    2
    3
    4
    5
    6
    7
    ALTER FOREIGN TABLE ft_region ADD CONSTRAINT constr_unique UNIQUE(R_REGIONKEY) NOT ENFORCED disable query optimization;
    
    SELECT relname,relhasindex FROM pg_class WHERE oid='ft_region'::regclass;
            relname         | relhasindex 
    ------------------------+-------------
            ft_region       | f
    (1 row)
    
    删除唯一信息约束:
    1
    ALTER FOREIGN TABLE ft_region DROP CONSTRAINT constr_unique CASCADE;
    
support.huaweicloud.com/sqlreference-830-dws/dws_06_0161.html