- Newest
- Most votes
- Most comments
Hello,
Firstly, I would like to inform you that if you GRANT USAGE privilege to a user over an external schema, then the user would be able to query all the tables under that external schema. This is an expected behavior.
You can achieve your use case by using materialized views instead of simple views. A materialized view contains a precomputed result set, based on an SQL query over one or more base tables. You can issue SELECT statements to query a materialized view, in the same way that you can query other tables or views in the database. Amazon Redshift returns the precomputed results from the materialized view, without having to access the base tables at all [1].
Please kindly refer the sample steps below,
-
Create a materialized view [2].
-
Grant SELECT access to this view to the concerned user/group using the below command,
- grant select on local_schema.materialized_view_name to username;
-
Now if you query the view from the concerned user, you would be successfully able to get the expected results, without giving explicit access to the user on your external schema.
However, here please note that, you would have to update the data in the materialized view, by refreshing it. Amazon Redshift identifies changes that have taken place in the base table or tables, and then applies those changes to the materialized view. As a materialized view owner, make sure to refresh materialized views whenever a base table changes.
References - [1] https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-overview.html [2] https://docs.aws.amazon.com/redshift/latest/dg/materialized-view-create-sql-command.html
Relevant content
- Accepted Answerasked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
Thanks for the response. Please note the underlying external table gets dropped and recreated, hence I was creating a late binding view. Since materialized view would not work no schema binding, do we have any alternate option here?