List views in PostgreSQL database with their scripts

This query returns list of non-system views in a database with their definition.

Query

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;

Columns

  • schema_name - view's schema name
  • view_name - view name
  • view_definition - view's definition

Rows

  • One row represents one view
  • Scope of rows: non-system views in a database
  • Ordered by schema and view name

Sample results