CREATE VIEW

An SQL command for defining a view

CREATE VIEW is a DDL command for defining a view.

CREATE VIEW has always been present in PostgreSQL.

Change history

Examples

Basic usage example for CREATE VIEW:

postgres=# CREATE VIEW bar AS SELECT * FROM foo WHERE id % 2 <> 0;
CREATE VIEW

postgres=# \d+ bar 
                             View "public.bar"
 Column |  Type   | Collation | Nullable | Default | Storage | Description 
--------+---------+-----------+----------+---------+---------+-------------
 id     | integer |           |          |         | plain   | 
View definition:
 SELECT foo.id
   FROM foo
  WHERE (foo.id % 2) <> 0;

postgres=# INSERT INTO foo VALUES (1),(2),(3);
INSERT 0 3

postgres=# SELECT * FROM bar ;
 id 
----
  1
  3
(2 rows)

Categories

DDL, SQL command

See also

ALTER VIEW, DROP VIEW, CREATE MATERIALIZED VIEW