ALTER_MATERIALIZED_VIEW(7pg18)

๐Ÿ“ฆ version 18.6, in opensuse-leap 16.0

๐Ÿ’– 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, if NO is 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 ๐Ÿ‘‘


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