forked from HiFX/amazon-redshift-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v_get_view_priv_by_user.sql
30 lines (30 loc) · 1.07 KB
/
v_get_view_priv_by_user.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**********************************************************************************************
Purpose: View to get the views that a user has access to
History:
2013-10-29 jjschmit Created
2016-05-24 chriz-bigdata addressed edge case for objects with names containing '.'
**********************************************************************************************/
CREATE OR REPLACE VIEW admin.v_get_view_priv_by_user
AS
SELECT
*
FROM
(
SELECT
schemaname
,viewname
,usename
,HAS_TABLE_PRIVILEGE(usrs.usename, obj, 'select') AS sel
,HAS_TABLE_PRIVILEGE(usrs.usename, obj, 'insert') AS ins
,HAS_TABLE_PRIVILEGE(usrs.usename, obj, 'update') AS upd
,HAS_TABLE_PRIVILEGE(usrs.usename, obj, 'delete') AS del
,HAS_TABLE_PRIVILEGE(usrs.usename, obj, 'references') AS ref
FROM
(SELECT schemaname, viewname, QUOTE_IDENT(schemaname) || '.' || QUOTE_IDENT(viewname) AS obj FROM pg_views ) AS objs
INNER JOIN
(SELECT * FROM pg_user) AS usrs
ON 1 = 1
ORDER BY obj
)
WHERE sel = true or ins = true or upd = true or del = true or ref = true
;