Last active
January 25, 2017 14:53
-
-
Save mcanaves/b8791a72fdbf1d94a6f3f87239cd85c2 to your computer and use it in GitHub Desktop.
Execute a query over all schemas on a postgres db
This file contains hidden or 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 s record; | |
BEGIN | |
FOR s IN SELECT n.nspname AS schema | |
FROM pg_catalog.pg_namespace AS n | |
WHERE n.nspname NOT LIKE 'pg_%' AND n.nspname <> 'information_schema' | |
LOOP | |
RAISE NOTICE '%', s; | |
EXECUTE FORMAT('<QUERY ON %I>', s.schema); | |
END LOOP; | |
END; $$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment