Created
March 24, 2017 08:55
-
-
Save vskrachkov/a0db0ce68a9422a1d5be0ac02c5fc6df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
n.nspname as "schema" | |
,t.relname as "table" | |
,c.relname as "index" | |
,i.indisunique AS "is_unique" | |
,array_to_string(array_agg(a.attname), ', ') as "columns" | |
,pg_get_indexdef(i.indexrelid) || ';' as "ddl" | |
,'DROP INDEX ' || n.nspname || '.' || c.relname || ';' as "delete_ddl" | |
FROM pg_catalog.pg_class c | |
JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace | |
JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid | |
JOIN pg_catalog.pg_class t ON i.indrelid = t.oid | |
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(i.indkey) | |
WHERE c.relkind = 'i' | |
and n.nspname in ('public') | |
and (t.relname like 'main_%' or t.relname like 'proxy_%') | |
GROUP BY | |
n.nspname | |
,t.relname | |
,c.relname | |
,i.indisunique | |
,i.indexrelid | |
ORDER BY | |
n.nspname | |
,t.relname | |
,c.relname; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment