From: Albert Loo <albertsql@hotmail.com>
To: pgsql-sql@postgresql.org
Subject: query to do a backward 'skip', possible with (index) optimization ?
Date: Mon, 10 Jan 2000 21:15:39 MYT
Message-ID: <20000110131539.77866.qmail@hotmail.com> (raw)
hi,
Coming from xbase background and having just started on sql, I tried sql
queries that does xbase 'skip'. I wanted to implement record browsing with
'Next' and 'Previous' features. Currently, I'm testing this with a table of
about 20,000 rows using psql.
I'm able to perform 'forward skip' query with :
=> select * from mytable where id > '12345' order by id limit 1;
- which returned what I wanted, 1 record with id value '12346'. Indexing on
id further optimised the query.
However, I'm unable to optimise query when doing a 'backward skip'. I've
tried :
=> select * from mytable where id < '12345' order by id desc limit 1;
- which returned the correct result '12344', but without optimization.
I was hoping a descending order index key would optimise it, but I think
postgresql don't support it (yet ?).
Next, I tried using offset -1...which is not possible either :)
=> select * from mytable where id > '12345' order by id limit 1 offset -1;
ERROR: parser: parse error at or near "-"
Has anyone tried 'backward skip' with optimization ?
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
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: albertsql@hotmail.com
Subject: Re: query to do a backward 'skip', possible with (index) optimization ?
In-Reply-To: <20000110131539.77866.qmail@hotmail.com>
References: <20000110131539.77866.qmail@hotmail.com>
* 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