ALTER VIEW modifies all auxiliary attributes of a view. (To modify the query definition of a view, use CREATE OR REPLACE VIEW.)
1 2 | ALTER VIEW [ IF EXISTS ] view_name ALTER [ COLUMN ] column_name SET DEFAULT expression; |
1 2 | ALTER VIEW [ IF EXISTS ] view_name ALTER [ COLUMN ] column_name DROP DEFAULT; |
1 2 | ALTER VIEW [ IF EXISTS ] view_name OWNER TO new_owner; |
1 2 | ALTER VIEW [ IF EXISTS ] view_name RENAME TO new_name; |
1 2 | ALTER VIEW [ IF EXISTS ] view_name SET SCHEMA new_schema; |
1 2 | ALTER VIEW [ IF EXISTS ] view_name SET ( { view_option_name [ = view_option_value ] } [, ... ] ); |
1 2 | ALTER VIEW [ IF EXISTS ] view_name RESET ( view_option_name [, ... ] ); |
1 2 | ALTER VIEW [ IF EXISTS ] view_name REBUILD; |
1 2 | ALTER VIEW [ IF EXISTS ] ONLY view_name REBUILD; |
If this option is specified, no error is reported if the view does not exist. Only a message is displayed.
Specifies the view name, which can be schema-qualified.
Value range: a string. It must comply with the naming convention.
Indicates an optional list of names to be used for columns of the view. If not given, the column names are deduced from the query.
Value range: a string. It must comply with the naming convention.
Sets or deletes the default value of a column. Currently, this parameter does not take effect.
Specifies the new owner of a view.
Specifies the new view name.
Specifies the new schema of the view.
This clause specifies optional parameters for a view.
Currently, the only parameter supported by view_option_name is security_barrier, which should be enabled when a view is intended to provide row-level security.
Value range: boolean type. It can be TRUE or FALSE.
The upper-layer cascading views become invalid in the following scenarios:
Only views and their dependent views are rebuilt. This function is available only if view_independent is set to on.
Create an example view myview:
1 2 | CREATE OR REPLACE VIEW myview AS SELECT * FROM pg_tablespace WHERE spcname = 'pg_default'; |
Rename a view.
1 | ALTER VIEW myview RENAME TO product_view; |
Change the schema of a view.
1 | ALTER VIEW product_view SET schema public; |
Rebuild a view.
1 | ALTER VIEW public.product_view REBUILD; |
Rebuild a dependent view.
1 | ALTER VIEW ONLY public.product_view REBUILD; |