Skip to content

Instantly share code, notes, and snippets.

@nini
Last active November 16, 2016 20:36
Show Gist options
  • Save nini/901f2d2b66b69f7d384a75461064f1b8 to your computer and use it in GitHub Desktop.
Save nini/901f2d2b66b69f7d384a75461064f1b8 to your computer and use it in GitHub Desktop.
Get complete index list for particular table as SQL
select pg_get_indexdef(idx.oid)||';'
from pg_index ind
join pg_class idx on idx.oid = ind.indexrelid
join pg_class tbl on tbl.oid = ind.indrelid
left join pg_namespace ns on ns.oid = tbl.relnamespace
where tbl.relname = 'mytablename'
and ns.nspname = 'public';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment