2

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?

asked Nov 17, 2021 at 8:58

1 Answer 1

3

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.