Skip to content

Instantly share code, notes, and snippets.

@BrianSigafoos
Created February 13, 2020 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrianSigafoos/6be5b6e2622ac8069a143274f7bb0ce0 to your computer and use it in GitHub Desktop.
Save BrianSigafoos/6be5b6e2622ac8069a143274f7bb0ce0 to your computer and use it in GitHub Desktop.
Postgresql snippets
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