On Fri, Apr 17, 2009 at 4:05 PM, koranthala <koranth...@gmail.com> wrote:

>
>
>
> On Apr 17, 11:57 pm, koranthala <koranth...@gmail.com> wrote:
> > On Apr 17, 11:51 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> >
> >
> >
> > > On Fri, Apr 17, 2009 at 2:47 PM, koranthala <koranth...@gmail.com>
> wrote:
> >
> > > > Hi,
> > > >    I am facing a problem which I believe should be a usual issue for
> > > > everyone. But I cannot find a way to do it in a straightforward
> > > > manner.
> > > >   I have to select a list of items from table A and delete everyone
> > > > of them. Now, there are close to 20K elements which I want to delete.
> > > > So, what I do now is:
> > > >    fields = tableA.filter(******)
> > > >    for field in fields:
> > > >      field.delete()
> >
> > > >   Now, this is invoking 20K separate messages to the DB - which is
> > > > rather suboptimal. However I think, I could not find a mechanism to
> > > > delete it in a straightway. One option I could think of is to create
> > > > raw SQL and invoke - but I would like to do that as the last resort.
> > > > Is there any other mechanism to do the same?
> >
> > > tableA.objects.filter(...).delete()
> >
> > > Won't pull in each of the objects to delete them:
> http://docs.djangoproject.com/en/dev/topics/db/queries/#topics-db-que...
> >
> > > Alex
> > > --
> > > "I disapprove of what you say, but I will defend to the death your
> right to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
> >
> > Thank you Alex.
>
> Sorry for troubling everyone further. But, I had a similar case of
> insert too - wherein I insert close to 2K elements at a time.
> Currently, I do it as
> list = []
> ...
> in some loop
> ...
> table = Table(values)
> list.append(table)
> ...
>
> for l in list: l.save()
>
> Is there something similar to block delete - for block insert too?
> >
>
Not right now there isn't no(although you don't need the intermediary list,
just save the items in the original loop, it will still do 2k queries, but
you won't be using a lot of memory storing 2k items).  There is a ticket
requesting a bulk insert, however I can't seem to find it now.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to