create or replace function ms_mv_theatre_ut() returns trigger
security definer language 'plpgsql' as $$
begin
  if old.id = new.id then
    perform movie_showtimes_refresh_row(ms.is)
      from movie_showtimes ms
    where ms.theatre_id = new.id;
  else
    perform movie_showtimes_refresh_row(ms.is)
      from movie_showtimes ms
    where ms.theatre_id = old.id;
    perform movie_showtimes_refresh_row(ms.is)
      from movie_showtimes ms
    where ms.theatre_id = new.id;
  end if;
  return null;
end
$$;

create or replace trigger ms_mv_theatre_ut after update on theatres
  for each row execute procedure ms_mv_theatre_ut();

