-
Notifications
You must be signed in to change notification settings - Fork 0
/
all_select.sql
30 lines (28 loc) · 875 Bytes
/
all_select.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
/*
*query current database all relations {table,view, materialized view, partitioned table}
that are allowed to 'SELECT' by every role (public).
*/
DROP VIEW all_select;
CREATE OR REPLACE VIEW public.all_select AS
SELECT
pn.nspname,
c.relname,
c.relkind,
pl.rolname AS owner
FROM
pg_class c
JOIN pg_namespace pn ON pn.oid = c.relnamespace
CROSS JOIN LATERAL aclexplode(COALESCE(c.relacl, acldefault('r'::"char", c.relowner))) s (grantor,
grantee,
privilege_type,
is_grantable)
JOIN pg_roles pl ON pl.oid = c.relowner
WHERE
s.privilege_type = 'SELECT'::text
AND (c.relkind = ANY (ARRAY['r'::"char", 'm'::"char", 'p'::"char", 'v'::"char"]))
AND s.grantee = 0::oid
ORDER BY
pn.nspname;
REVOKE ALL on public.all_select from public;
GRANT SELECT on public.all_select to public;
table all_select;