数据仓库服务 GAUSSDB(DWS)-系统表信息函数:pg_get_tabledef(table_oid)

时间:2024-01-26 16:15:18

pg_get_tabledef(table_oid)

描述:根据table_oid获取表定义。

返回类型:text

示例:先通过系统表pg_class获取表customer_t2的OID,再使用此函数查询表customer_t2的定义,可获取创建表customer_t2时的表字段,表的存储方式(行存或列存)及表的分布方式等信息。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
SELECT oid FROM pg_class WHERE relname ='customer_t2';
  oid
-------
 17353
(1 row)

SELECT * FROM pg_get_tabledef(17353);
              pg_get_tabledef
--------------------------------------------
 SET search_path = dbadmin;                +
 CREATE  TABLE customer_t2 (               +
         state_id character(2),            +
         state_name character varying(40), +
         area_id numeric                   +
 )                                         +
 WITH (orientation=column, compression=low)+
 DISTRIBUTE BY HASH(state_id)              +
 TO GROUP group_version1;
(1 row)
support.huaweicloud.com/sqlreference-820-dws/dws_06_0341.html