pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Stoyan Genov <genov@digsys.bg>
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?
Date: Sat, 06 Nov 1999 13:36:47 +0200
Message-ID: <199911061136.NAA00556@lorna.digsys.bg> (raw)
In-Reply-To: <38270488.5980775@smtp.telekabel.nl>

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




view thread (5+ messages)  latest in thread

Message-ID: <199911061136.NAA00556@lorna.digsys.bg>
Permalink:  ../199911061136.NAA00556@lorna.digsys.bg/
Also on:    postgresql.org/message-id/199911061136.NAA00556@lorna.digsys.bg

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: genov@digsys.bg, Alex@icepick.com
  Subject: Re: [SQL] How to get last 10 rows in a table on a large database?
  In-Reply-To: <199911061136.NAA00556@lorna.digsys.bg>
  References: <38270488.5980775@smtp.telekabel.nl> <199911061136.NAA00556@lorna.digsys.bg>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox