forked from awslabs/amazon-redshift-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v_get_tbl_priv_by_user.sql
28 lines (27 loc) · 1.01 KB
/
v_get_tbl_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
/**********************************************************************************************
Purpose: View to get the tables that a user has access to
History:
2013-10-29 jjschmit Created
**********************************************************************************************/
CREATE OR REPLACE VIEW admin.v_get_tbl_priv_by_user
AS
SELECT
*
FROM
(
SELECT
schemaname
,tablename
,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, tablename, '\"' + schemaname + '\"' + '.' + '\"' + tablename + '\"' AS obj FROM pg_tables where schemaname not in ('pg_internal')) AS objs
,(SELECT * FROM pg_user) AS usrs
ORDER BY obj
)
WHERE sel = true or ins = true or upd = true or del = true or ref = true
;