Received: from danbo.digsys.bg (root@danbo.digsys.bg [192.92.129.10]) by hub.org (8.9.3/8.9.3) with ESMTP id GAA28956 for ; Sat, 6 Nov 1999 06:36:53 -0500 (EST) (envelope-from genov@lorna.digsys.bg) Received: from lorna.digsys.bg (root@lorna.digsys.bg [193.68.6.15]) by danbo.digsys.bg (8.9.0/8.9.0) with ESMTP id NAA03726; Sat, 6 Nov 1999 13:36:49 +0200 (EET) Received: from lorna.digsys.bg (genov@localhost.digsys.bg [127.0.0.1]) by lorna.digsys.bg (8.9.0/8.9.0) with ESMTP id NAA00556; Sat, 6 Nov 1999 13:36:47 +0200 (EET) Message-Id: <199911061136.NAA00556@lorna.digsys.bg> X-Mailer: exmh version 2.0.2 2/24/98 To: Alex@icepick.com cc: pgsql-sql@postgresql.org Subject: Re: [SQL] How to get last 10 rows in a table on a large database? In-reply-to: Your message of "Sat, 06 Nov 1999 10:37:17 GMT." <38270488.5980775@smtp.telekabel.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Sat, 06 Nov 1999 13:36:47 +0200 From: Stoyan Genov Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by hub.org id GAA28976 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