创建一个自定义function

create or replace function grant_all_exec(schema_name varchar,select_or_insert varchar,grantee_user varchar) returns varchar as $$
DECLARE
funcrow varchar;
BEGIN
FOR funcrow IN select 'grant '||$2||' on '||$1||'.'||tablename||' to '||$3 from  pg_tables where schemaname=$1 
LOOP
EXECUTE funcrow;
END LOOP;
return 'grant '||$2||' to '||$3||' success!';
END;
$$ language plpgsql strict ;

 select grant_all_exec('hfods','select','hfods_read')

"grant select to hfods_read success!"

使用\dp hfods.t1 来查看是否授权成功

 

posted on 2018-05-29 18:21  洛丹伦的雪  阅读(189)  评论(0编辑  收藏  举报