<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def insert_select_max(self):
 """ SQL statement that inserts records with contiguous IDs, by selecting max ID from indexed table records. """

        if self._insert_select_max is None:
            if hasattr(self.record_class, 'application_name'):
                # Todo: Maybe make it support application_name without pipeline_id?
                assert hasattr(self.record_class, 'pipeline_id'), self.record_class
                tmpl = self._insert_select_max_tmpl + self._where_application_name_tmpl
            else:
                tmpl = self._insert_select_max_tmpl
            self._insert_select_max = self._prepare_insert(
                tmpl=tmpl,
                record_class=self.record_class,
                field_names=list(self.field_names),
            )
        return self._insert_select_max