CREATE OR REPLACE FUNCTION update_scheduled_episode_status() RETURNS TRIGGER AS $$ BEGIN UPDATE scheduled_episodes SET status = 'aired' WHERE air_date < CURRENT_DATE AND status = 'upcoming'; RETURN NEW; END; $$ LANGUAGE plpgsql;