Reshift授予验证HAS_TABLE_PRIVILEGE失败

时间:2016-11-08 08:24:38

标签: permissions amazon-redshift grant

我正在使用群组,模式和默认权限与Redshit拨款进行斗争。 当我尝试使用HAS_TABLE_PRIVILEGE

检查一切是否正确时
select tablename, 
   HAS_TABLE_PRIVILEGE('analyst', tablename, 'select') as select,
   HAS_TABLE_PRIVILEGE('analyst', tablename, 'insert') as insert,
   HAS_TABLE_PRIVILEGE('analyst', tablename, 'update') as update,
   HAS_TABLE_PRIVILEGE('analyst', tablename, 'delete') as delete, 
   HAS_TABLE_PRIVILEGE('analyst', tablename, 'references') as references 
from pg_tables
where schemaname='datalab'
order by tablename

我明白了:

An error occurred when executing the SQL command:
select tablename, 
   HAS_TABLE_PRIVILEGE('analyst', tablename, 'select') as select,
   HAS_TABLE_PRIVILEGE('analyst', tablena...

[Amazon](500310) Invalid operation: relation "dss__transaction" does not exist;

Execution time: 0.2s
1 statement failed.

这到底发生了什么?

1 个答案:

答案 0 :(得分:3)

我尝试过此操作,但pg_tables的第一个结果查询失败。在我的情况下,这是因为我需要明确说明每个表所在的模式。这对我有用:

WITH cte AS 
(
SELECT schemaname+'.'+tablename AS table_name
FROM pg_tables
WHERE schemaname = 'datalab'
)
SELECT table_name, 
   HAS_TABLE_PRIVILEGE('analyst', table_name, 'select') AS select,
   HAS_TABLE_PRIVILEGE('analyst', table_name, 'insert') AS insert,
   HAS_TABLE_PRIVILEGE('analyst', table_name, 'update') AS update,
   HAS_TABLE_PRIVILEGE('analyst', table_name, 'delete') AS delete, 
   HAS_TABLE_PRIVILEGE('analyst', table_name, 'references') AS references 
FROM cte
ORDER BY table_name ASC;