#
Create a View
This tutorial explains to you how to create a view in PostgreSQL. We use pgAdmin4 and a PostgreSQL 9.6.
Here are the steps for creating a View in PostgreSQL using the pgAdmin4 :
Right click on "Views", choose "Create", choose "View ...".
In the "General" tab, enter the name, the owner , the schema where the view will be created and the description of the view.
In the "Definition" tab, enter the SELECT of the view, if the view is a "Security Barrier" view and the "Check options".
Info
- Ordinary views are updatable in 9.3, but security_barrier views aren't considered "simple" views and are not updatable.
- security_barrier views implement row-level security.
- If "Check option" is used, all INSERT and UPDATE commands on the view will be checked to ensure data satisfy the view-defining condition (that is, the new data would be visible through the view). If they do not, the update will be rejected.
In the "Security" tab, enter the Privileges and Security labels for the view (not mandatory).
You can click on SQL tab to see the SQL command used for creating that view.
Click on "Save" to create that view.
CREATE OR REPLACE VIEW "mySchema"."myView" AS
SELECT "EMP".id,
"EMP".firstname,
"EMP".surname
FROM "mySchema"."EMP";
ALTER TABLE "mySchema"."myView"
OWNER TO postgres;