Hi Daniel,

You should probably take a look at the executemany method of the cursor. Your insert times might drop by a factor 20 . Here's an example.

Cheers,

Fedor

import time
import MySQLdb


db=MySQLdb.Connect(user="me",passwd="my password",db="test") c=db.cursor() n=0 tic=time.time() for i in range(3000): n+=c.execute('INSERT INTO testtable VALUES (%s)', (i,)) toc=time.time() t1=toc-tic print 'separate sql statements: %s, inserted %s records' % (t1,n)



tic=time.time()
n=c.executemany('INSERT INTO testtable VALUES (%s)', [(i,) for i in range(3000)])
toc=time.time()
t2=toc-tic
print 'all at once %s inserted %s records' % (t2,n)


OUTPUT>>>
separate sql statements: 0.571248054504, inserted 3000 records
all at once 0.0253219604492 inserted 3000 records


-- http://mail.python.org/mailman/listinfo/python-list

Reply via email to