PostgreSQL 9.3: ALTER VIEW AS

postgresql, postgresql-9.3

Solution

You have to drop and recreate the view:

DROP VIEW IF EXISTS View1;
CREATE VIEW View1 AS SELECT * FROM Table1;

If you only added columns, without renaming already existing columns or change the type, you could use CREATE OR REPLACE without DROP VIEW first, but is safer to drop explicitly and than recreate the view.

Using only CREATE OR REPLACE would throw a error if the order, the name or the type of the columns was changed.

Problem

I am using PostgreSQL 9.3 version. I need to alter the view because of the table have been changed(added more columns) . Well! I have tried the following script which does not work for me: ``` ALTER VIEW View1 AS SELECT * FROM Table1; ``` Got an error: ``` Syntax error near 'AS' ```

Original source