And here is the tested version of the code I published earlier

while True:
    ids = [row[0] for row in
session.query(Movie.id).filter(Movie.year>50).limit(30)]
    if len(ids) == 0: break

session.query(Movie).filter(Movie.id.in_(ids)).delete(synchronize_session=False)
    session.flush()
session.commit()

-- 
Mike Conley



On Wed, May 27, 2009 at 9:13 AM, Gregg Lind <gregg.l...@gmail.com> wrote:

>
> I believe by "map function", Timothy may be implying that you should
> use any of the python idioms for converting iterables of tuples to a
> straight tuple.  The one I like best
>
> from itertools import chain
> q = session.query(User.name)  #(User is a class)
> names = itertools.chain(*q.all() )
>
> But you could use generator comprehensions (  names = (x[0] for x in
> q.all()),  operator.itemgetter, or map instead.
>
> Correct me, Timothy, if necessary.
>
> Gregg
>
>
> On Wed, May 27, 2009 at 6:25 AM, Harish Vishwanath
> <harish.shas...@gmail.com> wrote:
> > Thanks!
> >
> > Could you elaborate on how you use the map function? I couldn't find it
> > myself in the docs.
> >
> > Regards,
> > Harish
> >
> >
> > On Wed, May 27, 2009 at 3:07 PM, Timothy N. Tsvetkov
> > <timothy.tsvet...@gmail.com> wrote:
> >>
> >> Q1. Good question %) I didn't find anything about it in docs (but i
> >> didn't search a lot), so i use map function to convert it to a list
> >> you want. And I think it is the right solution. Because if you query
> >> for more then one column (session.query(User.is, User.name).all()) a
> >> list of tuples is what you want to get as a result. So i think it is
> >> good, that it works the same way for one or more then one query
> >> params.
> >>
> >> On May 26, 9:10 pm, Harish Vishwanath <harish.shas...@gmail.com>
> >> wrote:
> >> > Hello,
> >> >
> >> > Question 1:
> >> >
> >> > When there is a query like below :
> >> >
> >> > q = session.query(User.name)  #(User is a class)
> >> >
> >> > and when I do q.all(), a list of tuples (User.name,) is returned
> though
> >> > a
> >> > single column is asked for. Is there a way to get a list directly from
> >> > q.all() when a single column is required?
> >> >
> >> > Question 2:
> >> >
> >> > I need to delete a bulky table and I want to print diagnostics after n
> >> > number of deletes. Is there a way to use Query object so that a SQL
> >> > statement like below can be generated?
> >> >
> >> > " delete from movie where year in (select top 30 year from movie where
> >> > year
> >> >
> >> > > 50); ", so that a  message can be logged after every 30 deletes.
> >> >
> >> > I am using Sqlite DB.
> >> >
> >> > Regards,
> >> > Harish
> >>
> >
> >
> > >
> >
>
> >
>

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

Reply via email to