Last active
April 12, 2022 22:59
-
-
Save clarkbw/acb0f15036ac46057085f1f5838110de to your computer and use it in GitHub Desktop.
quick postgres SQL for replacing an index
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
-- get existing index names and SQL definitions | |
SELECT indexname, indexdef | |
FROM pg_indexes | |
WHERE schemaname = 'public' AND tablename = 'table' | |
ORDER BY indexname; | |
-- create new tmp index (example) | |
CREATE INDEX tmp_name_of_the_index ON public.table USING btree (time ASC); | |
-- drop existing index | |
DROP INDEX name_of_the_index; | |
-- mv the tmp index to the previous name | |
ALTER INDEX tmp_name_of_the_index RENAME TO name_of_the_index; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment