Redshift view definition permissions issue

Viewed 1070

Running this query, even as postgres login, displays view_definition only for the views that are created by the current login.

select table_schema as schema_name, table_name as view_name, view_definition from information_schema.views where table_schema not in ('information_schema', 'pg_catalog') order by schema_name, view_name;

Is there some way to get view definition for all views no matter who created them?

If not i plan to just make a job in my etl scheduler to reassign all views to owner postgres.

2 Answers

Information_schema.views returns NULL for view_definition if the current user (even admin) is not the owner of the view [1]. This is how it is designed in Postgres and since Redshift is based on Postgres 8.0.2, I assume it has a similar behavior.

The v_generate_view_ddl [2] admin view in AWS's GitHub repo could help in getting all view definitions.

References:
[1] Postgres Documentation - https://www.postgresql.org/docs/8.0/infoschema-views.html
[2] Redshift Admin View - https://github.com/awslabs/amazon-redshift-utils/blob/master/src/AdminViews/v_generate_view_ddl.sql

You could just use "show view" command and it will show the view definition irrespective of who created it in redshift.

show view <nameoftheview>
Related