Created
April 18, 2018 13:42
-
-
Save rjdp/dac2e8e0bc7bb7f7d6b63d23651955fb to your computer and use it in GitHub Desktop.
Loop over schemas in a Postgresql database and execute arbitrary DDL example
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 | |
schemaname name; | |
BEGIN | |
FOR schemaname IN SELECT nspname FROM pg_namespace WHERE nspname LIKE 'schema_%' AND nspname <> 'information_schema' LOOP | |
RAISE NOTICE 'Running Alter on Schema : %', schemaname; | |
EXECUTE format('ALTER TABLE %I.common_commonconfigure ADD COLUMN google_secret_key varchar(150);', schemaname); | |
END LOOP; | |
END; | |
$$ LANGUAGE plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment