PostgreSQL View

PostgreSQL View

The PostgreSQL commands:
– CREATE VIEW is used to create a view.
– ALTER VIEW is used to change view name.
– DROP VIEW is used to delete a view.

View syntax

-- create view
CREATE [OR REPLACE] VIEW 
view_name AS SELECT * query;

-- alter view
ALTER VIEW [ IF EXISTS ] 
view_name RENAME TO new_view_name;

-- drop view
DROP VIEW [ IF EXISTS ] view_name;

View example

CREATE VIEW goods_view 
AS SELECT * FROM goods;

ALTER VIEW goods_view 
RENAME TO pg_goods_view;

DROP VIEW pg_goods_view;