ALTER VIEW

An SQL command for modifying a view

ALTER VIEW is a DDL command for modifying a view.

ALTER VIEW was added in PostgreSQL 8.3.

Usage

ALTER VIEW can be used to modify various properties and attributes of a view. However it cannot be used to change the underlying definition; this can only be done with the CREATE OR REPLACE VIEW ... syntax.

For historical reasons, ALTER TABLE can be used as an alternative to ALTER VIEW for syntax which is valid for both tables and views.

Change history

Examples

Basic usage example for ALTER VIEW:

postgres=# ALTER VIEW bar RENAME TO baz;
ALTER VIEW

ALTER TABLE can be used on views as long as the syntax used is valid for views:

postgres=# ALTER TABLE baz RENAME TO boo;
ALTER TABLE

postgres=# \d boo
                 View "public.boo"
 Column |  Type   | Collation | Nullable | Default 
--------+---------+-----------+----------+---------
 id     | integer |   

Using ALTER TABLE syntax not valid for views:

postgres=# ALTER TABLE boo SET TABLESPACE foo;
ERROR:  ALTER action SET TABLESPACE cannot be performed on relation "boo"
DETAIL:  This operation is not supported for views.

Categories

DDL, SQL command

See also

CREATE VIEW, DROP VIEW, ALTER MATERIALIZED VIEW