coryd.dev/queries/triggers/update_scheduled_status.psql

10 lines
233 B
Text

CREATE OR REPLACE FUNCTION update_scheduled_episode_status()
RETURNS TRIGGER AS $$
BEGIN
IF NEW.air_date < CURRENT_DATE AND NEW.status = 'upcoming' THEN
NEW.status := 'aired';
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;