With select matviewname from pg_matviews
I get all materialized views in the database. How can I filter the result to get only those the current user has select grant (= read permission) on?
1 Answer 1
You can use the function has_table_privilege()
to check that:
select mv.*
from pg_catalog.pg_matviews mv
where has_table_privilege(format('%I.%I', mv.schemaname, mv.matviewname), 'select')
The version with two parameters checks this for the current user. Alternatively you can use the version with three parameters and pass the user name explicitly.
answered Nov 17, 2021 at 9:16
user1822user1822
lang-sql