]> begriffs open source - ai-pg/blob - full-docs/txt/sql-alterview.txt
Convert HTML docs to more streamlined TXT
[ai-pg] / full-docs / txt / sql-alterview.txt
1
2 ALTER VIEW
3
4    ALTER VIEW — change the definition of a view
5
6 Synopsis
7
8 ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expressio
9 n
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
12  | SESSION_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] [, ..
17 . ] )
18 ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] )
19
20 Description
21
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.)
24
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
31    any view anyway.)
32
33 Parameters
34
35    name
36           The name (optionally schema-qualified) of an existing view.
37
38    column_name
39           Name of an existing column.
40
41    new_column_name
42           New name for an existing column.
43
44    IF EXISTS
45           Do not throw an error if the view does not exist. A notice is
46           issued in this case.
47
48    SET/DROP DEFAULT
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.
54
55    new_owner
56           The user name of the new owner of the view.
57
58    new_name
59           The new name for the view.
60
61    new_schema
62           The new schema for the view.
63
64    SET ( view_option_name [= view_option_value] [, ... ] )
65           RESET ( view_option_name [, ... ] )
66           Sets or resets a view option. Currently supported options are:
67
68         check_option (enum)
69                 Changes the check option of the view. The value must be
70                 local or cascaded.
71
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.
75
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.
79
80 Notes
81
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.
85
86 Examples
87
88    To rename the view foo to bar:
89 ALTER VIEW foo RENAME TO bar;
90
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
97
98 Compatibility
99
100    ALTER VIEW is a PostgreSQL extension of the SQL standard.
101
102 See Also
103
104    CREATE VIEW, DROP VIEW