ALTER_VIEW(7pg15)
πΈ NAME πΈ
Okay bestie, welcome to the ALTER_VIEW manual page from the PostgreSQL 15.19 docs. Itβs giving βchange the definition of a view,β but make it auxiliary-properties-only π
.
β¨ SYNOPSIS β¨
ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name SET DEFAULT expression
ALTER VIEW [ IF EXISTS ] name ALTER [ COLUMN ] column_name DROP DEFAULT
ALTER VIEW [ IF EXISTS ] name OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
ALTER VIEW [ IF EXISTS ] name RENAME [ COLUMN ] column_name TO new_column_name
ALTER VIEW [ IF EXISTS ] name RENAME TO new_name
ALTER VIEW [ IF EXISTS ] name SET SCHEMA new_schema
ALTER VIEW [ IF EXISTS ] name SET ( view_option_name [= view_option_value] [, ... ] )
ALTER VIEW [ IF EXISTS ] name RESET ( view_option_name [, ... ] )
π DESCRIPTION π
So <pink>bestie</pink>, ALTER VIEW changes various auxiliary properties of a view. If you actually want to modify the viewβs defining query, use CREATE OR REPLACE VIEW β that is literally the move for that, no cap.
You must own the view to use ALTER VIEW. To change a viewβs schema, you must also have CREATE privilege on the new schema. To alter the owner, you must also be a direct or indirect member of the new owning role, and that role must have CREATE privilege on the viewβs schema. These restrictions enforce that altering the owner doesnβt do anything you couldnβt do by dropping and recreating the view. However, a superuser can alter ownership of any view anyway. periodt. π
π PARAMETERS π
nameβ the name (optionally schema-qualified) of an existing view. Very βtell me who you areβ energy.column_nameβ name of an existing column.new_column_nameβ new name for an existing column.IF EXISTSβ do not throw an error if the view does not exist. A notice is issued in this case. So itβs not silent-silent, itβs notice-cute. π«ΆSET/DROP DEFAULTβ these forms set or remove the default value for a column. A view columnβs default value is substituted into anyINSERTorUPDATEcommand whose target is the view, before applying any rules or triggers for the view. The viewβs default will therefore take precedence over any default values from underlying relations. Important detail, bestie β the viewβs default is main character here. πnew_ownerβ the user name of the new owner of the view.new_nameβ the new name for the view.new_schemaβ the new schema for the view.SET ( view_option_name [= view_option_value] [, ... ] )RESET ( view_option_name [, ... ] )
These set or reset a view option. Currently supported options are:
check_option(enum) β changes the check option of the view. The value must belocalorcascaded.security_barrier(boolean) β changes the security-barrier property of the view. The value must be a Boolean value, such astrueorfalse.security_invoker(boolean) β changes the security-invoker property of the view. The value must be a Boolean value, such astrueorfalse.
π«Ά NOTES π«Ά
For historical reasons, ALTER TABLE can be used with views too; but the only variants of ALTER TABLE that are allowed with views are equivalent to the ones shown above. Cute lore, but thatβs the whole note. π¦
π EXAMPLES π
To rename the view foo to bar:
ALTER VIEW foo RENAME TO bar;
To attach a default column value to an updatable view:
CREATE TABLE base_table (id int, ts timestamptz);
CREATE VIEW a_view AS SELECT * FROM base_table;
ALTER VIEW a_view ALTER COLUMN ts SET DEFAULT now();
INSERT INTO base_table(id) VALUES(1); -- ts will receive a NULL
INSERT INTO a_view(id) VALUES(2); -- ts will receive the current time
π₯ COMPATIBILITY π₯
ALTER VIEW is a PostgreSQL extension of the SQL standard. So itβs not standard-standard, itβs PostgreSQL-iconic. β¨
π¦ SEE ALSO π¦
CREATE VIEW(CREATE_VIEW(7))DROP VIEW(DROP_VIEW(7))
byeee π β this page is from PostgreSQL 15.19, dated 2026, signing off with maximum view-altering energy. π
π¦ where this page comes from
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql15 15.19-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms