postgresql refresh function

if you have postgresql view that needs to be refreshed immediately after the parent model has changed you need to define a function and a trigger to do so.

the function:
create or replace function refresh_model_view()
returns trigger language plpgsql
as $$
begin
refresh materialized view model;
return null;
end $$;

the trigger
create trigger refresh_model_view_trigger
after insert or update or delete or truncate
on parent_model for each statement
execute procedure refresh_model_view();