Cute Happy Ghost
본문 바로가기
DB/Postgresql

postgresql DB에있는 모든 컬럼 조회 및 테이블별 정렬, 해당 테이블 컬럼조회

by JENN_tech7 2022. 5. 25.
728x90
SMALL

DB에있는 모든 컬럼 조회 및 테이블별 정렬

SELECT TABLE_NAME as 테이블이름, column_name as 컬럼명,  
is_nullable as null가능여부,  
data_type as 데이터타입,  
character_maximum_length as 최대길이,  
character_octet_length,  
numeric_precision,  
numeric_precision_radix,  
numeric_scale  
  FROM INFORMATION_SCHEMA.COLUMNS 
 WHERE TABLE_CATALOG = 'DB이름'
 and table_schema = '스키마이름' 
 ORDER BY 테이블이름, ORDINAL_POSITION;

 

 

 

예) public스키마의 test데이터베이스내의 tableA의 모든 컬럼명만 조회 

SELECT column_name as 컬럼명
  FROM INFORMATION_SCHEMA.COLUMNS 
 WHERE TABLE_CATALOG = 'test'
 and table_schema = 'public'
 and table_name = 'tableA';
728x90
LIST

댓글