If you use rows = cursor.fetchall()
you have already executed the query and the result is a list of RowProxy's returned by the query. Count then is simply count = len(rows) Otherwise, the count(*) approach is correct. -- Mike Conley On Fri, Mar 13, 2009 at 4:42 PM, jeff <jeffre...@gmail.com> wrote: > > thanks i will use select count (*) > > i was making a leap that there would be something in pgdb which allows > a function like: > > sql_txt = "select * from addresses" > cursor.execute(sql_txt) > rows=cursor.fetchall() > rows_returned = cursor_result.rowcount > > where the rowcount property contains the number of rows returned by > the select statement defined and executed. > > just wanted to see whether such a property was available in sqlalchemy > using the relational expression interface. > > > On Mar 13, 9:38 am, "Michael Bayer" <mike...@zzzcomputing.com> wrote: > > database cursors are essentially iterators so a total rowcount, without > > fetching all the rows, is not available in a platform-agnostic way. > > > > the usual strategy to find out how many rows of something exist in the DB > > is to do SELECT COUNT(*). > > > > > > > > Stephen Emslie wrote: > > > > > Well, I would have expected ResultProxy.rowcount to do just that > > > (return the number of rows in the last executed statement) but I just > > > get 0 from it. Perhaps someone could explain how to use it correctly. > > > > > Stephen Emslie > > > > > On Thu, Mar 12, 2009 at 5:20 PM, jeff <jeffre...@gmail.com> wrote: > > > > >> hi. this question should be easy. i've searched around though and > > >> haven't found the answer. all i want to do is know the number of > > >> records in a result set i get using an execute statement with a simple > > >> select. so if i do: > > > > >> s=select([raw_table],and_(raw_table.c.name==m > > >> ['name'],raw_table.c.as_of>=i['first_time'])) > > >> rec_list=conn.execute(s) > > > > >> is there a simple way to get back the number of records that exist in > > >> rec_list? > > > > >> thanks, i'm sure it's simple and i missed something.- Hide quoted text > - > > > > - Show quoted text - > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---