REFRESH_MATERIALIZED_VIEW(7pg13)
π REFRESH_MATERIALIZED_VIEW π
okay so bestie, welcome to the REFRESH_MATERIALIZED_VIEW page from the PostgreSQL 13.23 Documentation β¨ this is the one that's gonna teach you how to swap out everything inside a materialized view, no cap π«Ά
β¨ NAME β¨
REFRESH_MATERIALIZED_VIEW β replace the contents of a materialized view π₯
π SYNOPSIS π
REFRESH MATERIALIZED VIEW [ CONCURRENTLY ] name
[ WITH [ NO ] DATA ]
π¦ DESCRIPTION π¦
okay so REFRESH MATERIALIZED VIEW completely replaces the contents of a materialized view. Like, out with the old, in with the new, periodt π
to run this command you must be the owner of the materialized view β no owner, no refresh, that's the vibe check πΈ
the old contents are discarded. gone. bye π
if WITH DATA is specified (or just defaults, because it's the default), the backing query gets executed to provide the new data, and the materialized view is left in a scannable state β meaning you can actually read from it β¨
if WITH NO DATA is specified, no new data is generated and the materialized view is left in an unscannable state π«£
β οΈ important:CONCURRENTLYandWITH NO DATAmay not be specified together. like, at all. they do not mix, bestie π
π PARAMETERS π
CONCURRENTLYβ refresh the materialized view without locking out concurrent selects on that view. when you skip this option, a refresh that affects a lot of rows will tend to use fewer resources and complete more quickly β but it could block other connections that are trying to read from the materialized view π¬ this option may be faster in cases where a small number of rows are affected.
so here's the catch, and it's a big one π¨ this option is only allowed if there's at least one UNIQUE index on the materialized view which uses only column names and includes all rows β meaning it must not be an expression index or include a WHERE clause. iykyk.
also, this option may not be used when the materialized view is not already populated π
and even with this option, only one REFRESH at a time may run against any one materialized view. one. single. one. π
nameβ the name of the materialized view to refresh, optionally schema-qualified π·οΈ
π NOTES π
if there's an ORDER BY clause in the materialized view's defining query, the original contents of the materialized view will be ordered that way β cute! πΈ but REFRESH MATERIALIZED VIEW does not guarantee to preserve that ordering. so like... don't count on it, fr fr π
π EXAMPLES π
this command will replace the contents of the materialized view called order_summary using the query from the materialized view's definition, and leave it in a scannable state β¨:
REFRESH MATERIALIZED VIEW order_summary;
this command will free storage associated with the materialized view annual_statistics_basis and leave it in an unscannable state π«£:
REFRESH MATERIALIZED VIEW annual_statistics_basis WITH NO DATA;
β COMPATIBILITY β
REFRESH MATERIALIZED VIEW is a PostgreSQL extension π (so don't go looking for it in other databases, bestie)
π SEE ALSO π
CREATE MATERIALIZED VIEW(CREATE_MATERIALIZED_VIEW(7)) πALTER MATERIALIZED VIEW(ALTER_MATERIALIZED_VIEW(7)) π¦DROP MATERIALIZED VIEW(DROP_MATERIALIZED_VIEW(7)) πΈ
and that's the whole page, icon π this absolute classic is from PostgreSQL 13.23, dated 2025, officially filed under REFRESH ...IZED VIEW(7) β go refresh something and slay π
β¨π«Ά
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-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