]> begriffs open source - ai-pg/blob - full-docs/man7/ALTER_VIEW.7
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / man7 / ALTER_VIEW.7
1 '\" t
2 .\"     Title: ALTER VIEW
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 ALTER_VIEW \- change the definition of a view
32 .SH "SYNOPSIS"
33 .sp
34 .nf
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 [, \&.\&.\&. ] )
43 .fi
44 .SH "DESCRIPTION"
45 .PP
46 \fBALTER VIEW\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\&.)
49 .PP
50 You must own the view to use
51 \fBALTER VIEW\fR\&. To change a view\*(Aqs schema, you must also have
52 CREATE
53 privilege on the new schema\&. To alter the owner, you must be able to
54 SET ROLE
55 to the new owning role, and that role must have
56 CREATE
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\&.)
58 .SH "PARAMETERS"
59 .PP
60 \fIname\fR
61 .RS 4
62 The name (optionally schema\-qualified) of an existing view\&.
63 .RE
64 .PP
65 \fIcolumn_name\fR
66 .RS 4
67 Name of an existing column\&.
68 .RE
69 .PP
70 \fInew_column_name\fR
71 .RS 4
72 New name for an existing column\&.
73 .RE
74 .PP
75 IF EXISTS
76 .RS 4
77 Do not throw an error if the view does not exist\&. A notice is issued in this case\&.
78 .RE
79 .PP
80 SET/DROP DEFAULT
81 .RS 4
82 These forms set or remove the default value for a column\&. A view column\*(Aqs default value is substituted into any
83 \fBINSERT\fR
84 or
85 \fBUPDATE\fR
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\&.
87 .RE
88 .PP
89 \fInew_owner\fR
90 .RS 4
91 The user name of the new owner of the view\&.
92 .RE
93 .PP
94 \fInew_name\fR
95 .RS 4
96 The new name for the view\&.
97 .RE
98 .PP
99 \fInew_schema\fR
100 .RS 4
101 The new schema for the view\&.
102 .RE
103 .PP
104 SET ( \fIview_option_name\fR [= \fIview_option_value\fR] [, \&.\&.\&. ] )
105 .br
106 RESET ( \fIview_option_name\fR [, \&.\&.\&. ] )
107 .RS 4
108 Sets or resets a view option\&. Currently supported options are:
109 .PP
110 check_option (enum)
111 .RS 4
112 Changes the check option of the view\&. The value must be
113 local
114 or
115 cascaded\&.
116 .RE
117 .PP
118 security_barrier (boolean)
119 .RS 4
120 Changes the security\-barrier property of the view\&. The value must be a Boolean value, such as
121 true
122 or
123 false\&.
124 .RE
125 .PP
126 security_invoker (boolean)
127 .RS 4
128 Changes the security\-invoker property of the view\&. The value must be a Boolean value, such as
129 true
130 or
131 false\&.
132 .RE
133 .RE
134 .SH "NOTES"
135 .PP
136 For historical reasons,
137 \fBALTER TABLE\fR
138 can be used with views too; but the only variants of
139 \fBALTER TABLE\fR
140 that are allowed with views are equivalent to the ones shown above\&.
141 .SH "EXAMPLES"
142 .PP
143 To rename the view
144 foo
145 to
146 bar:
147 .sp
148 .if n \{\
149 .RS 4
150 .\}
151 .nf
152 ALTER VIEW foo RENAME TO bar;
153 .fi
154 .if n \{\
155 .RE
156 .\}
157 .PP
158 To attach a default column value to an updatable view:
159 .sp
160 .if n \{\
161 .RS 4
162 .\}
163 .nf
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
169 .fi
170 .if n \{\
171 .RE
172 .\}
173 .SH "COMPATIBILITY"
174 .PP
175 \fBALTER VIEW\fR
176 is a
177 PostgreSQL
178 extension of the SQL standard\&.
179 .SH "SEE ALSO"
180 CREATE VIEW (\fBCREATE_VIEW\fR(7)), DROP VIEW (\fBDROP_VIEW\fR(7))