Skip to content

Instantly share code, notes, and snippets.

@wildintellect
Created May 19, 2014 18:23
Show Gist options
  • Save wildintellect/fd9dff9e926eb0ffe6ff to your computer and use it in GitHub Desktop.
Save wildintellect/fd9dff9e926eb0ffe6ff to your computer and use it in GitHub Desktop.
Listing all GIST indexes in a Postgis database.
SELECT i.relname as indexname,
idx.indrelid::regclass as tablename,
am.amname as typename,
ARRAY(
SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
FROM generate_subscripts(idx.indkey, 1) as k
ORDER BY k
) as indkey_names
FROM pg_index as idx
JOIN pg_class as i
ON i.oid = idx.indexrelid
JOIN pg_am as am
ON i.relam = am.oid
JOIN pg_namespace as ns
ON ns.oid = i.relnamespace
AND ns.nspname = ANY(current_schemas(false))
Where am.amname Like 'gist';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment