CREATE TRIGGER trigger_update_days_read AFTER UPDATE OF progress ON books FOR EACH ROW WHEN (OLD.progress IS DISTINCT FROM NEW.progress AND (NEW.read_status = 'started' OR NEW.read_status = 'finished')) EXECUTE FUNCTION update_days_read();