Re: [SQL] query to do a backward 'skip', possible with (index) optimization ?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Albert Loo" <albertsql(at)hotmail(dot)com>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] query to do a backward 'skip', possible with (index) optimization ?
Date: 2000-01-10 15:17:49
Message-ID: 3114.947517469@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Albert Loo" <albertsql(at)hotmail(dot)com> writes:
> => select * from mytable where id < '12345' order by id desc limit 1;

> - which returned the correct result '12344', but without optimization.

6.5.* doesn't know how to do that using an index (but 7.0 will). I seem
to recall that someone posted a patch that partially solved the problem
in 6.5.* sources; check the archives if you are in a hurry.

BTW, I think you're probably going at this the wrong way, because it
doesn't extend to the case of fetching the *next* record in a
prespecified query. You probably want to use DECLARE CURSOR and FETCH.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Alain TESIO 2000-01-10 19:14:06 Re: [SQL] query to do a backward 'skip', possible with (index) optimization ?
Previous Message Jude Weaver 2000-01-10 09:21:13 Simmultanous Connections