Skip to content

Instantly share code, notes, and snippets.

@mcanaves
Last active January 25, 2017 14:53
Show Gist options
  • Save mcanaves/b8791a72fdbf1d94a6f3f87239cd85c2 to your computer and use it in GitHub Desktop.
Save mcanaves/b8791a72fdbf1d94a6f3f87239cd85c2 to your computer and use it in GitHub Desktop.
Execute a query over all schemas on a postgres db
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