PostgreSQL – How to List All Views

To list views in a PostgreSQL database, you can use SQL queries to query the system catalog tables. Specifically, you can query the pg_views catalog table to retrieve information about the views in the database. Here’s how you can do it:

SELECT table_name FROM information_schema.views WHERE table_schema = 'public';

where

  • table_name is the name of the view.
  • information_schema.views is the system catalog table that stores information about views.
  • table_schema = 'public' restricts the query to views in the “public” schema. If your views are in a different schema, replace ‘public’ with the appropriate schema name.

This query will return a list of view names in the specified schema. If you want to see additional information about the views, you can modify the query accordingly. For example, to retrieve the schema name and view name, you can use the following query:

SELECT table_schema, table_name FROM information_schema.views WHERE table_schema = 'public';

This query will display both the schema name and view name for each view in the “public” schema.

PostgreSQL views are typically stored in the “public” schema by default, but they can also be created in other schemas. Adjust the table_schema condition to match the schema where your views are located.

Similar Posts