In point of fact, when doing mass inserts, serious attention needs to be paid to how frequently to commit, and what to do about failures and other exceptional behavior. (What happens when record 999 of 1000 blows up on a key violation -- how do you correctly insert as much data as possible? Or do you backup the database before you start, and restore from the backup if anything fails?)
- Craig -
On Mon, Dec 27, 2010 at 16:55, Silva Paulo <psdasilva@yahoo.com> wrote:
From the documentation ...
Pls.: you want the "try " part instead of transaction.commit() alone because if something went wrong you still want the rollback.
transaction.commit()
from django.db import transaction
@transaction.commit_manually
def viewfunc(request):
...
# You can commit/rollback however and whenever you want
...
# But you've got to remember to do it yourself!
try:
...
except:
transaction.rollback()
else:
transaction.commit()
--- On Mon, 12/27/10, derek <gamesbook@gmail.com> wrote:
> From: derek <gamesbook@gmail.com>
> Subject: Re: Massive insertion of records
> To: "Django users" <django-users@googlegroups.com>
> Date: Monday, December 27, 2010, 11:29 AM
> Can you explain what you mean by
> "manual commitments" (preferably with
> a code example)?
>
> Thanks
> Derek
>
> On Dec 26, 4:38 am, Silva Paulo <psdasi...@yahoo.com>
> wrote:
> > OK. I found a "solution".
> > Using manual commitments after lots of insertions (ex.
> >1000) makes the massive insertion very fast (at least
> for my needs).
> >
> > Thanks to all who answered.
> >
> > --- On Fri, 12/24/10, Silva Paulo <psdasi...@yahoo.com>
> wrote:
> >
> >
> >
> >
> >
> >
> >
> > > From: Silva Paulo <psdasi...@yahoo.com>
> > > Subject: Massive insertion of records
> > > To: "newbie" <django-users@googlegroups.com>
> > > Date: Friday, December 24, 2010, 6:26 PM
> > > I need to do a massive insertion of
> > > records in two tables "connectd" by "foreignkey".
> Is there a
> > > way, using the Django db API, to do it.
> e=Foo(...);e.save()
> > > seems too slow.
> >
> > > Thanks
> >
> > >
> >
> > > --
> > > You received this message because you are
> subscribed to the
> > > Google Groups "Django users" group.
> > > To post to this group, send email to django-users@googlegroups.com.
> > > To unsubscribe from this group, send email to
> > > django-users+unsubscribe@googlegroups.com.
> > > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the
> Google Groups "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment