def prep_insert(self):
        sql = """
            INSERT INTO "%(model_table)s" (%(model_fields)s) (
            SELECT %(temp_fields)s
            FROM "%(temp_table)s");
        """
        options = dict(
            model_table=self.model._meta.db_table,
            temp_table=self.temp_table_name,
        )

        model_fields = []

        for field, header in self.field_header_crosswalk:
            model_fields.append('"%s"' % field.get_attname_column()[1])

        for k in self.static_mapping.keys():
            model_fields.append('"%s"' % k)

        options['model_fields'] = ", ".join(model_fields)

        temp_fields = []
        for field, header in self.field_header_crosswalk:
            string = '"%s"' % header
            if hasattr(field, 'copy_template'):
                string = field.copy_template % dict(name=header)
            template_method = 'copy_%s_template' % field.name
            if hasattr(self.model, template_method):
                template = getattr(self.model(), template_method)()
                string = template % dict(name=header)
            temp_fields.append(string)
        for v in self.static_mapping.values():
            temp_fields.append("'%s'" % v)
        options['temp_fields'] = ", ".join(temp_fields)
        return sql % options
Creates a INSERT statement that reorders and cleans up
dataset/ETHPy150Open california-civic-data-coalition/django-postgres-copy/postgres_copy/__init__.py/CopyMapping.prep_insert