Skip to content

Instantly share code, notes, and snippets.

@MatthiasKunnen
Last active December 27, 2018 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthiasKunnen/5e0b433b77c24e97cda2e89cbfb21b7f to your computer and use it in GitHub Desktop.
Save MatthiasKunnen/5e0b433b77c24e97cda2e89cbfb21b7f to your computer and use it in GitHub Desktop.
Postgres
select
t.relname as table_name,
array_to_string(array_agg(a.attname), ', ') as column_names,
i.relname as index_name
from
pg_class t,
pg_class i,
pg_index ix,
pg_attribute a
where
t.oid = ix.indrelid
and i.oid = ix.indexrelid
and a.attrelid = t.oid
and a.attnum = ANY(ix.indkey)
and t.relkind = 'r'
and t.relname not like 'pg%'
group by
t.relname,
i.relname
order by
t.relname,
i.relname;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment