PostgreSQL中是否有一个命令用于删除特定角色拥有的所有视图和函数?我不明白所有内部表是如何连接在一起的,以便我可以创建这样的命令。
答案 0 :(得分:1)
删除观点:
Invalid Input
删除功能:
create function drop_views_by_owner(owner regrole, do_drop boolean default true)
returns setof text language plpgsql as $$
declare r text;
begin
for r in
select format('%s.%s', nspname, relname)
from pg_class c
join pg_namespace n on n.oid = relnamespace
where c.relowner = $1
and relkind = 'v'
loop
if do_drop then
execute format('drop view %s', r);
end if;
return next r;
end loop;
end $$;
如果第二个参数是create function drop_functions_by_owner(owner regrole, do_drop boolean default true)
returns setof text language plpgsql as $$
declare r text;
begin
for r in
select format('%s.%s(%s)',
nspname, proname, pg_get_function_identity_arguments(p.oid))
from pg_proc p
join pg_namespace n on n.oid = pronamespace
where p.proowner = $1
loop
if do_drop then
execute format('drop function %s', r);
end if;
return next r;
end loop;
end $$;
,则该函数不会删除对象:
false
答案 1 :(得分:0)
如果您的用户只拥有视图和功能,您可以简单地:
DROP OWNED BY your_role;
您必须为群集中用户拥有对象的每个数据库执行此操作。
您可能会发现此文档非常有用:https://www.postgresql.org/docs/current/static/role-removal.html