2016-11-08 87 views
2

我正在與團體,模式,默認權限的Redshit授予戰鬥。 當我嘗試檢查一切是正確使用HAS_TABLE_PRIVILEGE重新安置授權驗證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. 

到底發生在這裏?

回答

2

我試過這個,查詢失敗的第一個結果來自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;