Read the whole textbook, MATERIALIZED VIEW requires a REFRESH that is outside the transaction that made the change: https://www.postgresql.org/docs/current/rules-materializedvi...
Seriously, read a textbook:
http://db.cs.duke.edu/papers/fntdb12-ChirkovaYang-mat_views....