4 ALTER VIEW — change the definition of a view
8 ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expressio
10 ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name DROP DEFAULT
11 ALTER VIEW [ IF EXISTS ] name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER
13 ALTER VIEW [ IF EXISTS ] name RENAME [ COLUMN ] column_name TO new_column_name
14 ALTER VIEW [ IF EXISTS ] name RENAME TO new_name
15 ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema
16 ALTER VIEW [ IF EXISTS ] name SET ( view_option_name [= view_option_value] [, ..
18 ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] )
22 ALTER VIEW changes various auxiliary properties of a view. (If you want
23 to modify the view's defining query, use CREATE OR REPLACE VIEW.)
25 You must own the view to use ALTER VIEW. To change a view's schema, you
26 must also have CREATE privilege on the new schema. To alter the owner,
27 you must be able to SET ROLE to the new owning role, and that role must
28 have CREATE privilege on the view's schema. (These restrictions enforce
29 that altering the owner doesn't do anything you couldn't do by dropping
30 and recreating the view. However, a superuser can alter ownership of
36 The name (optionally schema-qualified) of an existing view.
39 Name of an existing column.
42 New name for an existing column.
45 Do not throw an error if the view does not exist. A notice is
49 These forms set or remove the default value for a column. A view
50 column's default value is substituted into any INSERT or UPDATE
51 command whose target is the view, before applying any rules or
52 triggers for the view. The view's default will therefore take
53 precedence over any default values from underlying relations.
56 The user name of the new owner of the view.
59 The new name for the view.
62 The new schema for the view.
64 SET ( view_option_name [= view_option_value] [, ... ] )
65 RESET ( view_option_name [, ... ] )
66 Sets or resets a view option. Currently supported options are:
69 Changes the check option of the view. The value must be
72 security_barrier (boolean)
73 Changes the security-barrier property of the view. The
74 value must be a Boolean value, such as true or false.
76 security_invoker (boolean)
77 Changes the security-invoker property of the view. The
78 value must be a Boolean value, such as true or false.
82 For historical reasons, ALTER TABLE can be used with views too; but the
83 only variants of ALTER TABLE that are allowed with views are equivalent
84 to the ones shown above.
88 To rename the view foo to bar:
89 ALTER VIEW foo RENAME TO bar;
91 To attach a default column value to an updatable view:
92 CREATE TABLE base_table (id int, ts timestamptz);
93 CREATE VIEW a_view AS SELECT * FROM base_table;
94 ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
95 INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL
96 INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time
100 ALTER VIEW is a PostgreSQL extension of the SQL standard.
104 CREATE VIEW, DROP VIEW