본문 바로가기

카테고리 없음

postgresql 도멘인 넣기. 컬럼 사이즈등등

insert into tb_cm_domain (
domain_nm,
domain_cd,
data_type,
	rmk,
	crt_dtm
)
select 
domain_nm,
domain_cd,
data_type,
ARRAY_TO_STRING(ARRAY_AGG(table_name ORDER BY table_name),',') rmk,
now()
from  (
select 
b.description  domain_nm
,a.column_name  domain_cd
,a.data_type ||  case when character_maximum_length is not null then '('||character_maximum_length||')' else '' end as data_type
,a.table_name 
--,a.ordinal_position 
from information_schema.columns a
left outer join pg_catalog.pg_description b
on b.objsubid = a.ordinal_position
inner join pg_class c
on b.objoid=c.oid 
and c.relname =a.table_name
where 1=1 
and a.table_schema='public'
--a.table_name='tb_opt10001';
) ta
group by 
domain_nm,
domain_cd,
data_type