Created
November 9, 2021 10:58
-
-
Save redsfyre/18dec03354203cd54d04f9a663c38d80 to your computer and use it in GitHub Desktop.
Query that drops all indexes in the given table. Note: unique keys are not affected by this operation.
This file contains 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
DO | |
$do$ | |
DECLARE | |
_sql text; | |
BEGIN | |
SELECT 'DROP INDEX ' || string_agg(indexrelid::regclass::text, ', ') | |
FROM pg_index i | |
LEFT JOIN pg_depend d ON d.objid = i.indexrelid | |
AND d.deptype = 'i' | |
WHERE i.indrelid = 'TABLE_NAME'::regclass -- Replace the TABLE_NAME with your table's name | |
AND d.objid IS NULL | |
INTO _sql; | |
IF _sql IS NOT NULL THEN | |
EXECUTE _sql; | |
END IF; | |
END | |
$do$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment