ALTER_MATERIALIZED_VIEW(7)
๐ ALTER MATERIALIZED VIEW ๐
okay bestie, welcome to ALTER_MATERIALIZED_VIEW(7) from the PostgreSQL 18.6 Documentation, and no cap this page is your little glow-up station for materialized views โจ
โจ NAME โจ
ALTER_MATERIALIZED_VIEW โ change the definition of a materialized view ๐
๐ธ SYNOPSIS ๐ธ
ALTER MATERIALIZED VIEW [ IF EXISTS ] name
action [, ... ]
ALTER MATERIALIZED VIEW name
[ NO ] DEPENDS ON EXTENSION extension_name
ALTER MATERIALIZED VIEW [ IF EXISTS ] name
RENAME [ COLUMN ] column_name TO new_column_name
ALTER MATERIALIZED VIEW [ IF EXISTS ] name
RENAME TO new_name
ALTER MATERIALIZED VIEW [ IF EXISTS ] name
SET SCHEMA new_schema
ALTER MATERIALIZED VIEW ALL IN TABLESPACE name [ OWNED BY role_name [, ... ] ]
SET TABLESPACE new_tablespace [ NOWAIT ]
where action is one of:
ALTER [ COLUMN ] column_name SET STATISTICS integer
ALTER [ COLUMN ] column_name SET ( attribute_option = value [, ... ] )
ALTER [ COLUMN ] column_name RESET ( attribute_option [, ... ] )
ALTER [ COLUMN ] column_name SET STORAGE { PLAIN | EXTERNAL | EXTENDED | MAIN | DEFAULT }
ALTER [ COLUMN ] column_name SET COMPRESSION compression_method
CLUSTER ON index_name
SET WITHOUT CLUSTER
SET ACCESS METHOD new_access_method
SET TABLESPACE new_tablespace
SET ( storage_parameter [= value] [, ... ] )
RESET ( storage_parameter [, ... ] )
OWNER TO { new_owner | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
like look at all those little knobs you can turn ๐ obsessed.
๐ฆ DESCRIPTION ๐ฆ
ALTER MATERIALIZED VIEW changes various auxiliary properties of an existing materialized view. it's giving "tweak the settings, don't rebuild the whole thing" ๐
okay so here's the tea on permissions ๐ซ you must own the materialized view to use ALTER MATERIALIZED VIEW. and if you wanna change a materialized view's schema, you also need CREATE privilege on the new schema. and to alter the owner? you gotta be able to SET ROLE to the new owning role, and that role has to have CREATE privilege on the materialized view's schema. why so strict?? because these restrictions enforce that altering the owner doesn't do anything you couldn't do by dropping and recreating the materialized view. periodt. that's the whole point of the gatekeeping ๐
but bestie, plot twist: a superuser can alter ownership of any view anyway. no cap. ๐
and here's the part that makes this page so easy: the statement subforms and actions available for ALTER MATERIALIZED VIEW are a subset of those available for ALTER TABLE, and they have the exact same meaning when used for materialized views. so if you want the details, go read the descriptions for ALTER TABLE. iykyk ๐
๐ PARAMETERS ๐
nameโ the name (optionally schema-qualified) of an existing materialized view. she needs to already exist, we're not manifesting here ๐ซcolumn_nameโ name of an existing column.extension_nameโ the name of the extension that the materialized view is to depend on (or no longer dependent on, ifNOis specified). and here's the dramatic part: a materialized view that's marked as dependent on an extension is automatically dropped when the extension is dropped. it's giving ride-or-die, they go down together ๐new_column_nameโ new name for an existing column.new_ownerโ the user name of the new owner of the materialized view.new_nameโ the new name for the materialized view.new_schemaโ the new schema for the materialized view.
โญ EXAMPLES โญ
to rename the materialized view foo to bar:
ALTER MATERIALIZED VIEW foo RENAME TO bar;
so simple, so clean, she ate ๐ โจ
๐ COMPATIBILITY ๐
ALTER MATERIALIZED VIEW is a PostgreSQL extension. not standard SQL, she's homegrown ๐ซถ
๐ SEE ALSO ๐
CREATE MATERIALIZED VIEW(CREATE_MATERIALIZED_VIEW(7))DROP MATERIALIZED VIEW(DROP_MATERIALIZED_VIEW(7))REFRESH MATERIALIZED VIEW(REFRESH_MATERIALIZED_VIEW(7))
okay that's the whole page bestie, go forth and alter some views ๐ธ๐ and as always: this was PostgreSQL 18.6, dated 2026, ALTER MA...IZED VIEW(7) โ mwah, bye ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms