Last active
August 29, 2015 14:04
-
-
Save rocksfrow/af751f120c7e2c713ca5 to your computer and use it in GitHub Desktop.
plPgsql function to output grant SQL to give user access to entire schema
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
create or replace function fetch_schema_grants(_user text, _schema text) RETURNS TABLE(query text) as | |
$func$ | |
begin | |
RETURN QUERY select 'grant all on schema '||_schema||' to '||_user||';' union all select 'grant all on sequence '||sequence_schema||'.'||sequence_name||' to '||_user||';' from information_schema.sequences where sequence_schema=_schema union all select 'grant all on '||schemaname||'.'||tablename||' to '||_user||';' from pg_tables where schemaname=_schema; | |
end | |
$func$ language plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ex)