PostgreSQL、华为DWS查询表字段类型、字段描述

PostgreSQL查询表字段的详细信息(字段名、字段类型、字段描述等):

# 实际使用中需要修改TABLE_SCHEMA和TABLE_NAME 
SELECT AA.*,BB.DESC FROM
  (SELECT
		A.ORDINAL_POSITION AS COL_NUM,
		A.COLUMN_NAME AS COL_NAME,
		A.DATA_TYPE AS COL_TYPE,
		A.CHARACTER_MAXIMUM_LENGTH AS COL_LEN,
		A.NUMERIC_PRECISION AS COL_PREC,
		A.DATETIME_PRECISION AS COL_TIME_PREC,
		A.IS_NULLABLE AS COL_NULLABLE,
		A.COLUMN_DEFAULT AS COL_DEFAULT
	FROM INFORMATION_SCHEMA.COLUMNS A
	WHERE A.TABLE_SCHEMA = 'public' AND A.TABLE_NAME = 'table_name'
  )AS AA LEFT JOIN
  (
	SELECT
		OBJSUBID,
		DESCRIPTION AS DESC
	FROM PG_DESCRIPTION
	WHERE OBJOID =(SELECT RELID FROM PG_STAT_ALL_TABLES WHERE SCHEMANAME = 'public' AND RELNAME = 'table_name')
  )AS BB ON AA.COL_NUM = BB.OBJSUBID ORDER BY AA.COL_NUM;

华为云数据中台DWS基于PostgreSQL开发,经测试以上SQL在DWS中同样适用。

你可能感兴趣的:(华为云,postgresql,华为,数据库,dws)