3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "ALTER VIEW" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 ALTER_VIEW \- change the definition of a view
35 ALTER VIEW [ IF EXISTS ] \fIname\fR ALTER [ COLUMN ] \fIcolumn_name\fR SET DEFAULT \fIexpression\fR
36 ALTER VIEW [ IF EXISTS ] \fIname\fR ALTER [ COLUMN ] \fIcolumn_name\fR DROP DEFAULT
37 ALTER VIEW [ IF EXISTS ] \fIname\fR OWNER TO { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
38 ALTER VIEW [ IF EXISTS ] \fIname\fR RENAME [ COLUMN ] \fIcolumn_name\fR TO \fInew_column_name\fR
39 ALTER VIEW [ IF EXISTS ] \fIname\fR RENAME TO \fInew_name\fR
40 ALTER VIEW [ IF EXISTS ] \fIname\fR SET SCHEMA \fInew_schema\fR
41 ALTER VIEW [ IF EXISTS ] \fIname\fR SET ( \fIview_option_name\fR [= \fIview_option_value\fR] [, \&.\&.\&. ] )
42 ALTER VIEW [ IF EXISTS ] \fIname\fR RESET ( \fIview_option_name\fR [, \&.\&.\&. ] )
47 changes various auxiliary properties of a view\&. (If you want to modify the view\*(Aqs defining query, use
48 \fBCREATE OR REPLACE VIEW\fR\&.)
50 You must own the view to use
51 \fBALTER VIEW\fR\&. To change a view\*(Aqs schema, you must also have
53 privilege on the new schema\&. To alter the owner, you must be able to
55 to the new owning role, and that role must have
57 privilege on the view\*(Aqs schema\&. (These restrictions enforce that altering the owner doesn\*(Aqt do anything you couldn\*(Aqt do by dropping and recreating the view\&. However, a superuser can alter ownership of any view anyway\&.)
62 The name (optionally schema\-qualified) of an existing view\&.
67 Name of an existing column\&.
72 New name for an existing column\&.
77 Do not throw an error if the view does not exist\&. A notice is issued in this case\&.
82 These forms set or remove the default value for a column\&. A view column\*(Aqs default value is substituted into any
86 command whose target is the view, before applying any rules or triggers for the view\&. The view\*(Aqs default will therefore take precedence over any default values from underlying relations\&.
91 The user name of the new owner of the view\&.
96 The new name for the view\&.
101 The new schema for the view\&.
104 SET ( \fIview_option_name\fR [= \fIview_option_value\fR] [, \&.\&.\&. ] )
106 RESET ( \fIview_option_name\fR [, \&.\&.\&. ] )
108 Sets or resets a view option\&. Currently supported options are:
112 Changes the check option of the view\&. The value must be
118 security_barrier (boolean)
120 Changes the security\-barrier property of the view\&. The value must be a Boolean value, such as
126 security_invoker (boolean)
128 Changes the security\-invoker property of the view\&. The value must be a Boolean value, such as
136 For historical reasons,
138 can be used with views too; but the only variants of
140 that are allowed with views are equivalent to the ones shown above\&.
152 ALTER VIEW foo RENAME TO bar;
158 To attach a default column value to an updatable view:
164 CREATE TABLE base_table (id int, ts timestamptz);
165 CREATE VIEW a_view AS SELECT * FROM base_table;
166 ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
167 INSERT INTO base_table(id) VALUES(1); \-\- ts will receive a NULL
168 INSERT INTO a_view(id) VALUES(2); \-\- ts will receive the current time
178 extension of the SQL standard\&.
180 CREATE VIEW (\fBCREATE_VIEW\fR(7)), DROP VIEW (\fBDROP_VIEW\fR(7))