Last active
October 13, 2015 01:47
-
-
Save fabriciocolombo/4119771 to your computer and use it in GitHub Desktop.
PostgreSQL - Change Owner
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
select 'ALTER FUNCTION ' || quote_ident(routine_schema) || '.' || quote_ident(routine_name) || ' OWNER TO ' ||routine_schema || ';' | |
from information_schema.routines | |
where specific_schema NOT LIKE E'pg\\_%' | |
and specific_schema <> 'information_schema' | |
and specific_schema <> 'public' | |
/*AND specific_schema = $YourSchema leave commented for all */ | |
union all | |
SELECT 'ALTER TABLE ' || quote_ident(s.nspname) || '.' || quote_ident(s.relname) || ' OWNER TO ' || nspname || ';' | |
FROM (SELECT nspname, relname | |
FROM pg_class c | |
JOIN pg_namespace n ON (c.relnamespace = n.oid) | |
WHERE nspname NOT LIKE E'pg\\_%' | |
AND nspname <> 'information_schema' | |
AND nspname <> 'public' | |
/*AND nspname = $YourSchema leave commented for all */ | |
and relkind IN ('r', 'S', 'v') | |
ORDER BY relkind = 'S') s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment