Skip to content

Instantly share code, notes, and snippets.

@leibowitz
Created March 1, 2018 14:00
Show Gist options
  • Save leibowitz/b13bc2d020aa30d5f213bb507c02cb1e to your computer and use it in GitHub Desktop.
Save leibowitz/b13bc2d020aa30d5f213bb507c02cb1e to your computer and use it in GitHub Desktop.
view permissions redshift table
SELECT *
FROM
(
SELECT
schemaname
,objectname
,usename
,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, ‘select’) AS sel
,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, ‘insert’) AS ins
,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, ‘update’) AS upd
,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, ‘delete’) AS del
,HAS_TABLE_PRIVILEGE(usrs.usename, fullobj, ‘references’) AS ref
FROM
(
SELECT schemaname, ‘t’ AS obj_type, tablename AS objectname, schemaname + ‘.’ + tablename AS fullobj FROM pg_tables
WHERE schemaname not in (‘pg_internal’)
UNION
SELECT schemaname, ‘v’ AS obj_type, viewname AS objectname, schemaname + ‘.’ + viewname AS fullobj FROM pg_views
WHERE schemaname not in (‘pg_internal’)
) AS objs
,(SELECT * FROM pg_user) AS usrs
ORDER BY fullobj
)
WHERE (sel = true or ins = true or upd = true or del = true or ref = true)
and schemaname=‘<opt schema>’
and objectname = ‘<tablename>’;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment