Re: [SQL] How to get last 10 rows in a table on a large database?

From: Stoyan Genov <genov(at)digsys(dot)bg>
To: Alex(at)icepick(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] How to get last 10 rows in a table on a large database?
Date: 1999-11-06 11:36:47
Message-ID: 199911061136.NAA00556@lorna.digsys.bg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi.
You should try this:
begin transaction;
declare tbl_cur cursor for select * from table order by datetime ASC;
fetch forward 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 .... .....
move forward 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

Browse pgsql-sql by date

  From Date Subject
Next Message Stoyan Genov 1999-11-06 11:44:34 Re: [SQL] pg_dump and "archive = none" ??
Previous Message Alex 1999-11-06 10:37:17 How to get last 10 rows in a table on a large database?