[Tutor] py-postgressql v1.0.1 question

Rance Hall ranceh at gmail.com
Mon Sep 13 00:18:49 CEST 2010

On Sun, Sep 12, 2010 at 4:54 PM, Luke Paireepinart
<rabidpoobear at gmail.com> wrote:
>> Thanks for the tip.  I'll do some more research but this sounds promising.
>> Rance
> Just be aware that some methods of list building will iterate over the list and evaluate it. So if you only want to retrieve the first 10 results but you do something like
> Results = [I.fetch() for I in cursor]
> print Results[:10]
> You will actually be retrieving all records.
> Obviously this is a contrived example and it will be more subtle in practice. Just be cautious that you're not fetching all your data initially and then paging it. You could maybe check your database for the number of results it's returning for each query maybe. I'm not very knowledgeable about database monitoring and optimization but this strikes me as something you could probably do.

Thanks for the warning here, and I had already suspected as much.  I
am making a calculated guess that there will only be at most 15-20
items at a time in the result set.  Getting all 20 and only choosing
the first 10 during the list iteration process seems to be the best
route.  Especially since sometimes I will want all of them.  If I just
play games with the iterator then I can reuse my get_list code other

If my calculated guess turns out to be wrong, and there are a
significant # of items in the list, then I can revisit this issue.


More information about the Tutor mailing list