본문 바로가기
Database/PostgreSQL

[PostgreSQL] 테이블 주석 및 컬럼 주석 조회

by 가가가가가가 2023. 11. 27.
반응형

테이블별 주석 조회

 

SELECT N.NSPNAME, C.RELNAME, OBJ_DESCRIPTION(C.OID) 
FROM PG_CATALOG.PG_CLASS C INNER JOIN PG_CATALOG.PG_NAMESPACE N ON C.RELNAMESPACE=N.OID 
WHERE C.RELKIND = 'r'
    AND NSPNAME = '[스키마명]'
    AND RELNAME = '[테이블명]'

 

컬럼별 주석 조회

 

SELECT
	PS.RELNAME AS TABLE_NAME,
	PA.ATTNAME AS COLUMN_NAME,
	PD.DESCRIPTION AS COLUMN_COMMENT
FROM PG_STAT_ALL_TABLES PS, PG_DESCRIPTION PD, PG_ATTRIBUTE PA
WHERE PD.OBJSUBID <> 0
	AND PS.RELID = PD.OBJOID
	AND PD.OBJOID = PA.ATTRELID
	AND PD.OBJSUBID = PA.ATTNUM
	AND PS.SCHEMANAME = '[스키마명]'
	AND PS.RELNAME = '[테이블명]'
ORDER BY PS.RELNAME, PD.OBJSUBID

 

 


참고

반응형

댓글