正如您可能已经注意到的,Redshift很难从中提取权限。处理数组会引发各种错误...
因为我使用自动程序管理Redshift的安全性,并且它依赖于组和用户授权,所以我需要知道用户如何获得权限:通过组或自定义用户授权。
使用所有在线资源,我创建了一个显示以上所有内容的视图。我知道这不是一个问题,但这是我发现共享代码的唯一方式,并且"回馈"对社区......
有没有人可以添加任何内容,建议进行改进?
SELECT nspname schema_name
, relname table_name
, pg_group.groname user_group
, pg_user.usename username
, case when charindex('U',split_part(split_part(array_to_string(nspacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('U',split_part(split_part(array_to_string(nspacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as schema_usage
, case when charindex('C',split_part(split_part(array_to_string(nspacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('C',split_part(split_part(array_to_string(nspacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as schema_obj_create
, case
when charindex('r',split_part(split_part(array_to_string(relacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('r',split_part(split_part(array_to_string(relacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as table_select
, case
when charindex('w',split_part(split_part(array_to_string(relacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('W',split_part(split_part(array_to_string(relacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as table_update
, case
when charindex('a',split_part(split_part(array_to_string(relacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('a',split_part(split_part(array_to_string(relacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as table_insert
, case
when charindex('d',split_part(split_part(array_to_string(relacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('d',split_part(split_part(array_to_string(relacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as table_delete
, case
when charindex('x',split_part(split_part(array_to_string(relacl, '|'),usename,2 ) ,'/',1)) > 0 then 'user'
when charindex('x',split_part(split_part(array_to_string(relacl, '|'),groname,2 ) ,'/',1)) > 0 then 'group'
end as table_reference
FROM pg_user
left join pg_group
on array_to_string(grolist, '|') like '%'||pg_user.usesysid||'%'
inner join pg_namespace
on array_to_string(nspacl, '|') like '%'||usename||'%'
or array_to_string(nspacl, '|') like '%group '||groname||'%'
left join pg_class AS objs
on relnamespace = pg_namespace.oid
and (array_to_string(relacl, '|') like '%'||usename||'%'
or array_to_string(relacl, '|') like '%group '||groname||'%')