Skip to content

Commit

Permalink
Improve insert performance using a transaction.
Browse files Browse the repository at this point in the history
  • Loading branch information
migonzalvar committed Jan 30, 2012
1 parent c663e36 commit 9ab787b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion csvkit/utilities/csvsql.py
Expand Up @@ -56,8 +56,12 @@ def main(self):
insert = sql_table.insert()
headers = csv_table.headers()

conn = engine.connect()
trans = conn.begin()
for row in csv_table.to_rows():
engine.execute(insert, [dict(zip(headers, row)), ])
conn.execute(insert, [dict(zip(headers, row)), ])
trans.commit()
conn.close()

# Writing to file
else:
Expand Down

0 comments on commit 9ab787b

Please sign in to comment.