[Twisted-web] my first post, writing a Web interface to a PostgreSQL db

L. Daniel Burr ldanielburr at mac.com
Fri Oct 14 07:25:43 MDT 2005

This is very simple to do, using the LIMIT OFFSET functionality in  

Just create a Resource which accepts a request arg indicating the offset,  
and then execute your query like so:

cursor.execute('SELECT foo, bar from mytable LIMIT 50 OFFSET %d' % offset)

As your users move forward and back through the dataset, you just change  
the offset.

If you are using Postgres, you should look at pgasync (search the mailing  
lists), which is a fully async (no threading) adapter for use with twisted  
and Postgres; awesome stuff.

The only real work to do here is to keep track of which offset your user  
currently is viewing, and that's trivial as well.

Hope this helps,

L. Daniel Burr

P.S.  There's an even cooler way to do this:  

On Fri, 14 Oct 2005 05:34:36 -0500, Michele Simionato  
<michele.simionato at gmail.com> wrote:

> I need to write a Web interface to a PostgreSQL database and I am
> considering to use Twisted for that. So, I have a few questions.
> First of all, I would like to know if there already something available
> that I should look at. Second, I have a more specific question.
> Suppose I have a large table with 1,000,000 records and a SELECT query
> that returns 1000 results and takes 10 minutes.
> I don't want my users to wait. I want to display the result of the
> query as an HTML table of 50 rows. The user should click, wait
> 30 seconds, see the result, then click a 'next' button to see
> the other 50 results, etc. In other words, I am looking for a lazy query
> functionality.
> Is that already available? If not, is it easy/difficult to implement?
> Thanks for any suggestion,
>         Michele Simionato
> _______________________________________________
> Twisted-web mailing list
> Twisted-web at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

More information about the Twisted-web mailing list