Re: best way to retreive the next record in a multi column index

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Merlin Moncure <merlin(dot)moncure(at)rcsonline(dot)com>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: best way to retreive the next record in a multi column index
Date: 2003-08-15 20:15:03
Message-ID: 20030815201503.GA14932@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Aug 15, 2003 at 13:42:23 -0400,
Merlin Moncure <merlin(dot)moncure(at)rcsonline(dot)com> wrote:
>
> Example:
> I have a table t with columns a, b, c. I have values a1, b1, c1 for
> those columns and would like to know the next value in the table when
> ordered by a, b. I have values a1, b1, and oid1 and would like to find
> the very next record in the table (essentially looking for the next
> record in the index).
>
> I have two solutions: one with 'or' logic and one with 'and' logic.
> Note: if the index we are scanning has the unique constraint, the oid
> part of the logic (and the index) can be left out.
>
How about something like the following:
select * from t
where a >= a1 and b >= b1
order by a, b limit 1 offset 1;

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message ohp 2003-08-15 20:36:22 Re: UnixWare on Current CVS: Success!
Previous Message Tom Lane 2003-08-15 19:18:23 Re: Bounds error in LockMethodInit().