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

时间:2024-12-24 10:32:39

示例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/gauss.db/region_orc11_64stripe')
    DISTRIBUTE BY roundrobin;
    
  • 查看region表是否有信息约束索引:
    1
    SELECT relname,relhasindex FROM pg_class WHERE oid='ft_region'::regclass;
    
    图1 查看relname
    1
    SELECT conname, contype, consoft, conopt, conindid, conkey FROM pg_constraint WHERE conname ='ft_region_pkey';
    
    图2 查看信息约束索引
  • 删除信息约束:
    1
    2
    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';
    
    图3 删除信息约束
  • 添加一个唯一信息约束:
    1
    ALTER FOREIGN TABLE ft_region ADD CONSTRAINT constr_unique UNIQUE(R_REGIONKEY) NOT ENFORCED;
    
    删除唯一信息约束:
    1
    2
    ALTER FOREIGN TABLE ft_region DROP CONSTRAINT constr_unique RESTRICT;
    SELECT conname, contype, consoft, conindid, conkey FROM pg_constraint WHERE conname ='constr_unique';
    
  • 添加一个唯一信息约束:
    1
    2
    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;
    
    删除唯一信息约束:
    1
    ALTER FOREIGN TABLE ft_region DROP CONSTRAINT constr_unique CASCADE;
    
support.huaweicloud.com/sqlreference-dws/dws_06_0161.html