1ALTER VIEW(7)            PostgreSQL 12.2 Documentation           ALTER VIEW(7)
2
3
4

NAME

6       ALTER_VIEW - change the definition of a view
7

SYNOPSIS

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_USER | SESSION_USER }
12       ALTER VIEW [ IF EXISTS ] name RENAME TO new_name
13       ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema
14       ALTER VIEW [ IF EXISTS ] name SET ( view_option_name [= view_option_value] [, ... ] )
15       ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] )
16

DESCRIPTION

18       ALTER VIEW changes various auxiliary properties of a view. (If you want
19       to modify the view's defining query, use CREATE OR REPLACE VIEW.)
20
21       You must own the view to use ALTER VIEW. To change a view's schema, you
22       must also have CREATE privilege on the new schema. To alter the owner,
23       you must also be a direct or indirect member of the new owning role,
24       and that role must have CREATE privilege on the view's schema. (These
25       restrictions enforce that altering the owner doesn't do anything you
26       couldn't do by dropping and recreating the view. However, a superuser
27       can alter ownership of any view anyway.)
28

PARAMETERS

30       name
31           The name (optionally schema-qualified) of an existing view.
32
33       IF EXISTS
34           Do not throw an error if the view does not exist. A notice is
35           issued in this case.
36
37       SET/DROP DEFAULT
38           These forms set or remove the default value for a column. A view
39           column's default value is substituted into any INSERT or UPDATE
40           command whose target is the view, before applying any rules or
41           triggers for the view. The view's default will therefore take
42           precedence over any default values from underlying relations.
43
44       new_owner
45           The user name of the new owner of the view.
46
47       new_name
48           The new name for the view.
49
50       new_schema
51           The new schema for the view.
52
53       SET ( view_option_name [= view_option_value] [, ... ] )
54       RESET ( view_option_name [, ... ] )
55           Sets or resets a view option. Currently supported options are:
56
57           check_option (string)
58               Changes the check option of the view. The value must be local
59               or cascaded.
60
61           security_barrier (boolean)
62               Changes the security-barrier property of the view. The value
63               must be Boolean value, such as true or false.
64
65

NOTES

67       For historical reasons, ALTER TABLE can be used with views too; but the
68       only variants of ALTER TABLE that are allowed with views are equivalent
69       to the ones shown above.
70

EXAMPLES

72       To rename the view foo to bar:
73
74           ALTER VIEW foo RENAME TO bar;
75
76       To attach a default column value to an updatable view:
77
78           CREATE TABLE base_table (id int, ts timestamptz);
79           CREATE VIEW a_view AS SELECT * FROM base_table;
80           ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
81           INSERT INTO base_table(id) VALUES(1);  -- ts will receive a NULL
82           INSERT INTO a_view(id) VALUES(2);  -- ts will receive the current time
83

COMPATIBILITY

85       ALTER VIEW is a PostgreSQL extension of the SQL standard.
86

SEE ALSO

88       CREATE VIEW (CREATE_VIEW(7)), DROP VIEW (DROP_VIEW(7))
89
90
91
92PostgreSQL 12.2                      2020                        ALTER VIEW(7)
Impressum