Re: [SQL] How to get last 10 rows in a table on a large database? - Mailing list pgsql-sql

From Stoyan Genov
Subject Re: [SQL] How to get last 10 rows in a table on a large database?
Date
Msg-id 199911061136.NAA00556@lorna.digsys.bg
Whole thread Raw
In response to How to get last 10 rows in a table on a large database?  (Alex@Icepick.com (Alex))
Responses Re: [SQL] How to get last 10 rows in a table on a large database?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi.
You should try this:begin transaction;    declare tbl_cur cursor for select * from table order by datetime ASC;
fetchforward 10 in tbl_cur;end transaction;
 

This is true if you want THE LAST 10 rows from the selection - you order it
in reverse and get the first 10. You are unable to say:begin transaction;    declare tbl_cur cursor for .... .....
moveforward all in tbl_cur;    fetch backward 10 in tbl_cur;    ...........end transaction;
 
because when you "move forward all" the result gets lost.

If something is unclear, do write back...

Stoyan Genov



pgsql-sql by date:

Previous
From: Alex@Icepick.com (Alex)
Date:
Subject: How to get last 10 rows in a table on a large database?
Next
From: Stoyan Genov
Date:
Subject: Re: [SQL] pg_dump and "archive = none" ??