On Fri, Jan 7, 2011 at 2:31 PM, Derek <gamesb...@gmail.com> wrote:
> Thomas
> That looks potentially useful - can you please give an example (on the
> webpage) of how to do a multi-row insertion?  I typically need to add
> thousands of rows from existing spreadsheets - am using xlrd to read the
> data, but if DSE could speed up the write-to-database operation, that would
> be incredibly useful.
> Thanks!


A quick example:

Given a model foo, defined as:

class foo(models.Model):
    name = models.CharField(max_length = 200)
    age = models.IntegerField()

you can insert 5000 records very easily like so:

       dex = dse.ModelDelayedExecutor(foo)
       for i in range(0, 5000):
           dex.addItem({'name': 'Person%s' % i, 'age': i})
       dex.close()

The thing is that while you`re adding items nothing happens SQL-wise
until you reach a specific limit, the default limit is 1000, then dse
executes a cursor.executemany(list of cached elements).
Another thing is the significant overhead of creating objects using
the django ORM and that slows things down as well.

The biggest performance gain is when you want to do inserts and
updates on a bunch of elements, like this:


       dex = dse.ModelDelayedExecutor(foo)
       for item in dex.getItems(): # will iterate over all records in
the foo-table
           item['name'] = '%s Doe' % item['name] # changing name here,
would probably alter a calculated value, something not possible using
SQL alone.
           dex.addItem(item)
       dex.close()

Regards,
Thomas

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to