タイトル通り。とりあえず版。


select * from (
	select 
	relname as TABLE_NAME 
	from pg_stat_user_tables
) as X
inner join (
	select 
	* 
	from information_schema.columns 
	where table_catalog='DB名' 
	and table_schema = 'スキーマ名'
) as Y
on X.TABLE_NAME = Y.table_name
left join (

	select
	tc.table_name as TABLE_NAME
	,ccu.column_name as COLUMN_NAME
	from information_schema.table_constraints tc,information_schema.constraint_column_usage ccu
	where tc.table_catalog='DB名'
	and tc.constraint_type='PRIMARY KEY'
	and tc.table_catalog=ccu.table_catalog
	and tc.table_schema=ccu.table_schema
	and tc.table_name=ccu.table_name
	and tc.constraint_name=ccu.constraint_name

) as Z
on X.TABLE_NAME = Z.TABLE_NAME
and X.TABLE_NAME = Z.table_name
and Y.table_name = Z.TABLE_NAME
and Y.column_name = Z.COLUMN_NAME