psycopg2 faster way to retrieve last x records
Luis P. Mendes
lupe at localhost.localdomain
Wed Nov 8 07:53:05 EST 2006
Em Tue, 07 Nov 2006 17:03:17 -0800, Stuart Bishop escreveu:
>
> The following SQL statement will return the last 200 rows in reverse order:
>
> SELECT * FROM seconds ORDER BY tempounix DESC LIMIT 200
>
> This will only send 200 rows from the server to the client (your existing
> approach will send all of the rows). Also, if you have an index on tempounix
> it will be really fast.
>
>
> If you really need the results in tempounix order, then:
>
> SELECT * FROM (
> SELECT * FROM seconds ORDER BY tempounix DESC LIMIT 200
> ) AS whatever
> ORDER BY tempounix;
Thank you Stuart, I'll try it.
Luis P. Mendes
More information about the Python-list
mailing list