"Albert Loo" <albertsql@hotmail.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