Javatpoint Logo

91-9990449935

 0120-4256464

PostgreSQL View

In PostgreSQL, a VIEW is a pseudo table. It is not a physical table but appear as ordinary table to select.

A view can also represent joined tables. It can contain all rows of a table or selected rows from one or more tables.

A View facilitates users to do the following:

  • It structures data in a natural and intuitive way and make it easy to find.
  • It restricts access to the data such that a user can only see limited data instead of complete data.
  • It summarizes data from various tables to generate reports.

PostgreSQL Create View

PostgreSQL view can be created by using CREATE VIEW statement. You can create it from a single table, multiple tables and another view.

Syntax:

PostgreSQL Create View Example

Consider a table "EMPLOYEES", having the following data.

postgre view

Now, we create a view from "EMPLOYEES" table. This view would contain only few columns from EMPLOYEES table:

Execute the following query:

postgre view

You can see this as:

postgre view

Now, you can retrieve data from the view "current_employees" as a simple query statement. You would see the following table:

postgre view

PostgreSQL DROP View

Follow these steps:

  • Select the view "current_employees" and make a right click on that.
  • You will see a Delete/Drop option, click on that.
  • You will see this:
  • postgre view
  • Click on the "Yes" button.
  • The View is dropped permanently. It is no anymore in the database.

You can also delete or drop a view by using the DROP VIEW command.

Syntax:

To delete the above example:

Next TopicPostgreSQL Join