Created
February 13, 2020 20:55
-
-
Save BrianSigafoos/6be5b6e2622ac8069a143274f7bb0ce0 to your computer and use it in GitHub Desktop.
Postgresql snippets
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
SELECT tablename FROM pg_tables WHERE schemaname = 'public'; | |
-- Move out of public | |
DO | |
$$ | |
DECLARE | |
row record; | |
BEGIN | |
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = 'public' -- and other conditions, if needed | |
LOOP | |
EXECUTE 'ALTER TABLE public.' || quote_ident(row.tablename) || ' SET SCHEMA valimail_defend_stage_reporting_20181127_super;'; | |
END LOOP; | |
END; | |
$$; | |
SELECT tablename FROM pg_tables WHERE schemaname = 'valimail_defend_stage_reporting_20181127_super'; | |
-- Move BACK to public | |
DO | |
$$ | |
DECLARE | |
row record; | |
BEGIN | |
FOR row IN SELECT tablename FROM pg_tables WHERE schemaname = 'valimail_defend_stage_reporting_20181127_super' -- and other conditions, if needed | |
LOOP | |
EXECUTE 'ALTER TABLE valimail_defend_stage_reporting_20181127_super.' || quote_ident(row.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