[Tutor] how best to implement paginated data in CLI

Rance Hall ranceh at gmail.com
Wed Sep 15 03:57:13 CEST 2010


On Tue, Sep 14, 2010 at 7:15 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> "Rance Hall" <ranceh at gmail.com> wrote
>
>> I'm using python 3.1 with py-postgresql (located at
>> http://python.projects.postgresql.org/
>>
>> I need to work through how best to paginate larger sql result sets.
>
> Its usually best to do that at the SQL level by controlling the cursor.
> I don't know PostGres but most SQL dialects allow you to control
> the number of result rows returned to the cursor then fetch the next
> group and the next etc. This will also potentially save a lot of network
> bandwidth (you only fetch the results you need which may not be
> all of them) and get your results back quicker for a big result set.
>
> HTH,
>
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/

Alan:

I think I need to refine my definition of large in my original question.

You are correct, but I think some more context might be in order.

A standard windows terminal window opens to run my app and it has
anywhere between 15 and 20 lines of text available for output.  (that
can be altered I know, but that has limits)

Some of those lines are taken up with formatting and the question and
input prompt at the bottom, so you have only room for 10 data elements
from your list,

In my case large is any recordset larger than the ten there is room
for on a single screen.

So the real question is how large is large?

I'm operating under the assumption that the size of the datasets Im
talking about are "small" in terms of what I usually think of when I
think of databases and networking, bandwidth and the like.  But large
in terms of the delivery mechanism (the windows terminal window)

I suspect that the extra network activity required to manage cursors
on a remote database is in my case meaningful.

I hope this sort of helps explain why I went where I went with my OP.

In reviewing the app I'm hoping to replace I found the size of the
client list is under 100 records.

Given this new information, do you still think that db cursors is the way to go?


More information about the Tutor mailing list