Created
October 8, 2012 06:15
-
-
Save garrow/3850987 to your computer and use it in GitHub Desktop.
Restore tables from a snapshot into public.
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 | |
$$ | |
DECLARE | |
hidden_table record; | |
BEGIN | |
FOR hidden_table IN | |
SELECT schemaname, tablename FROM pg_tables | |
WHERE schemaname = (SELECT MAX(schemaname) FROM pg_tables WHERE schemaname LIKE 'snapshot_%') | |
LOOP | |
EXECUTE 'DROP TABLE IF EXISTS public.' || quote_ident(hidden_table.tablename) || ';'; | |
EXECUTE 'ALTER TABLE ' || quote_ident(hidden_table.schemaname) || '.' || quote_ident(hidden_table.tablename) || ' SET SCHEMA public;'; | |
END LOOP; | |
END; | |
$$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment