Skip to content

Instantly share code, notes, and snippets.

@renatosuero
Created January 5, 2019 09:02
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 renatosuero/40ad1b6515b1a8df9cfc96d970402ee0 to your computer and use it in GitHub Desktop.
Save renatosuero/40ad1b6515b1a8df9cfc96d970402ee0 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION public.migrate_schema(change text)
RETURNS integer AS
$BODY$
DECLARE
v_schema text;
BEGIN
FOR v_schema IN
SELECT quote_ident(nspname)
FROM pg_namespace n
WHERE nspname !~~ 'pg_%'
AND nspname <> 'information_schema'
AND nspname <> 'public'
LOOP
EXECUTE 'SET LOCAL search_path = ' || v_schema;
EXECUTE change;
END LOOP;
return 1;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment