def _sql_bulk_insert_from_csv(self, conn, table, columns, data_file):
    if (conn.dialect.name in ('postgresql', 'psycopg2')):
        with conn.connection.cursor() as cursor:
            cursor.copy_expert('COPY {} ({}) FROM STDIN WITH (FORMAT CSV)'.format(table, ','.join(columns)), data_file)
    else:
        reader = unicodecsv.DictReader(data_file, columns)
        table = self.metadata.tables[table]
        rows = list(reader)
        if rows:
            conn.execute(table.insert().values(rows))
    self.session.flush()
def _sql_bulk_insert_from_csv(self, conn, table, columns, data_file):
    if (conn.dialect.name in ('postgresql', 'psycopg2')):
        with conn.connection.cursor() as cursor:
            cursor.copy_expert('COPY {} ({}) FROM STDIN WITH (FORMAT CSV)'.format(table, ','.join(columns)), data_file)
    else:
        reader = unicodecsv.DictReader(data_file, columns)
        table = self.metadata.tables[table]
        rows = list(reader)
        if rows:
            conn.execute(table.insert().values(rows))
    self.session.flush()