数据仓库服务 GAUSSDB(DWS)-PG_CONSTRAINT:应用示例

时间:2024-06-29 17:51:21

应用示例

查询指定表是否有主键。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
CREATE TABLE t1
(    
    C_CUSTKEY    BIGINT       ,
    C_NAME       VARCHAR(25)  ,
    C_ADDRESS    VARCHAR(40)  ,
    C_NATIONKEY  INT          ,
    C_PHONE      CHAR(15)     ,
    C_ACCTBAL    DECIMAL(15,2), 
    CONSTRAINT C_CUSTKEY_KEY PRIMARY KEY(C_CUSTKEY,C_NAME)
)
DISTRIBUTE BY HASH(C_CUSTKEY,C_NAME);

SELECT conname FROM pg_constraint WHERE conrelid = 't1'::regclass AND contype = 'p';
    conname
---------------
 c_custkey_key
(1 row)
support.huaweicloud.com/devg-830-dws/dws_04_0580.html