From: <gh...@gh...> - 2003-06-05 22:29:24
|
Steve Waterbury wrote: > I may be misunderstanding the purpose of > cursor.executemany(query, sequence_of_params) ... > > The doc says "Execute a query many times, once > for each params in the sequence." I had hoped > the results would accumulate in the cursor, but > it doesn't appear to (perhaps I'm doing something > wrong!). Here's what I'm doing: > > curs.executemany('select * from docs where doc_number = %s', docnums) executemany is not supposed to be used with SELECTs. Use it for INSERT or UPDATE only. > in which docnums is a list of strings, which are > values of doc_number. (I've verified that they are > valid.) Then when I then do > > curs.fetchall() > > ... I get only the result of the execution of the query > using the last item in the list (which is certainly what > you get by doing several "execute(query, parms)" > in succession). > > Is this the way it's supposed to work? > > And if so, what would be a good way of doing what I want to > do (i.e., feed in a sequence of parameters and get > back a cumulative result of executing the same > query with each one)? [...] In your particular example: docnums = [3,4,5,6] curs.execute("select * from docs where doc_number in %s", (docnums,)) Other problems will require other solutions. -- Gerhard |