PostgreSQL 테이블 컬럼 정보 조회

박제영·2023년 2월 28일

Database

목록 보기
1/2
   select tb.schemaname as 스키마명
	     ,tb.relname as 테이블명
	     ,tb_dc.description as 테이블설명
	     ,col.attname as 컬럼명
	     ,col.attnum as 컬럼순서
	     ,col_dc.description as 컬럼설명
	     ,col_type.data_type as 컬럼데이터타입
	     ,col_type.character_maximum_length as len
     from (select *
             from PG_STAT_ALL_TABLES
	        where RELNAME = 'table_name'
	          and schemaname='schema_name') tb--테이블정보
left join PG_DESCRIPTION tb_dc --테이블설명
       on tb_dc.OBJSUBID = 0
      and tb.RELID = tb_dc.OBJOID
left join PG_ATTRIBUTE col --컬럼정보
       on tb.relid=col.ATTRELID
left join PG_DESCRIPTION col_dc --컬럼설명
       on col_dc.OBJSUBID <> 0
      and tb.RELID = col_dc.OBJOID
      and col_dc.OBJOID = col.ATTRELID
      and col_dc.OBJSUBID = col.ATTNUM
left join INFORMATION_SCHEMA.COLUMNS col_type --컬럼데이터타입
       on col_type.table_schema=tb.schemaname
      and col_type.table_name=tb.relname
      and col_type.column_name=col.attname
      and col_type.ordinal_position=col.attnum
    where col.attstattarget ='-1'
 order by col.attnum;
profile
안녕하세요.

0개의 댓글