SELECT *
is expanded at execution time, just like with all similar operations (CREATE VIEW
, CREATE TABLE AS
)
The key word is "early binding" as opposed to "late binding". Postgres saves the list of columns present at execution time of SELECT *
, columns added later are not included automatically. The query string itself is not saved, only the internal representation after expanding SELECT *
and other stuff like resolving all identifiers.
REFRESH MATERIALIZED VIEW
never changes the data definition, only data:
REFRESH MATERIALIZED VIEW
completely replaces the contents of a materialized view.
The manual could be more explicit about it, but the comparison to the behavior of CREATE TABLE AS
made it clear for me:
CREATE MATERIALIZED VIEW
is similar toCREATE TABLE AS
, except that it also remembers the query used to initialize the view.