创建一个自定义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 来查看是否授权成功