1ALTER VIEW(7) PostgreSQL 14.3 Documentation ALTER VIEW(7)
2
3
4
6 ALTER_VIEW - change the definition of a view
7
9 ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expression
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 | SESSION_USER }
12 ALTER VIEW [ IF EXISTS ] name RENAME [ COLUMN ] column_name TO new_column_name
13 ALTER VIEW [ IF EXISTS ] name RENAME TO new_name
14 ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema
15 ALTER VIEW [ IF EXISTS ] name SET ( view_option_name [= view_option_value] [, ... ] )
16 ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] )
17
19 ALTER VIEW changes various auxiliary properties of a view. (If you want
20 to modify the view's defining query, use CREATE OR REPLACE VIEW.)
21
22 You must own the view to use ALTER VIEW. To change a view's schema, you
23 must also have CREATE privilege on the new schema. To alter the owner,
24 you must also be a direct or indirect member of the new owning role,
25 and that role must have CREATE privilege on the view's schema. (These
26 restrictions enforce that altering the owner doesn't do anything you
27 couldn't do by dropping and recreating the view. However, a superuser
28 can alter ownership of any view anyway.)
29
31 name
32 The name (optionally schema-qualified) of an existing view.
33
34 column_name
35 Name of an existing column.
36
37 new_column_name
38 New name for an existing column.
39
40 IF EXISTS
41 Do not throw an error if the view does not exist. A notice is
42 issued in this case.
43
44 SET/DROP DEFAULT
45 These forms set or remove the default value for a column. A view
46 column's default value is substituted into any INSERT or UPDATE
47 command whose target is the view, before applying any rules or
48 triggers for the view. The view's default will therefore take
49 precedence over any default values from underlying relations.
50
51 new_owner
52 The user name of the new owner of the view.
53
54 new_name
55 The new name for the view.
56
57 new_schema
58 The new schema for the view.
59
60 SET ( view_option_name [= view_option_value] [, ... ] )
61 RESET ( view_option_name [, ... ] )
62 Sets or resets a view option. Currently supported options are:
63
64 check_option (enum)
65 Changes the check option of the view. The value must be local
66 or cascaded.
67
68 security_barrier (boolean)
69 Changes the security-barrier property of the view. The value
70 must be Boolean value, such as true or false.
71
73 For historical reasons, ALTER TABLE can be used with views too; but the
74 only variants of ALTER TABLE that are allowed with views are equivalent
75 to the ones shown above.
76
78 To rename the view foo to bar:
79
80 ALTER VIEW foo RENAME TO bar;
81
82 To attach a default column value to an updatable view:
83
84 CREATE TABLE base_table (id int, ts timestamptz);
85 CREATE VIEW a_view AS SELECT * FROM base_table;
86 ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
87 INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL
88 INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time
89
91 ALTER VIEW is a PostgreSQL extension of the SQL standard.
92
94 CREATE VIEW (CREATE_VIEW(7)), DROP VIEW (DROP_VIEW(7))
95
96
97
98PostgreSQL 14.3 2022 ALTER VIEW(7)