Skip to content

Instantly share code, notes, and snippets.

@hooopo
Created July 26, 2019 06:53
Show Gist options
  • Save hooopo/ecd007240775ca381f7765a1334447ca to your computer and use it in GitHub Desktop.
Save hooopo/ecd007240775ca381f7765a1334447ca to your computer and use it in GitHub Desktop.
select
kcu.table_name,
array_agg(kcu.column_name::text order by kcu.ordinal_position asc) as key_column
from information_schema.table_constraints tco
join information_schema.key_column_usage kcu on kcu.constraint_name = tco.constraint_name
and kcu.constraint_schema = tco.constraint_schema
and kcu.constraint_name = tco.constraint_name
where tco.constraint_type = 'PRIMARY KEY'
group by 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment