1

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?

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.