Re: How do you select from a table until a condition is met?

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Nicholas Allen <nallen(at)freenet(dot)co(dot)uk>
Cc: Dmitry Tkach <dmitry(at)openratings(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: How do you select from a table until a condition is met?
Date: 2003-02-12 19:35:38
Message-ID: 20030212193538.GA29724@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Feb 12, 2003 at 20:10:15 +0100,
Nicholas Allen <nallen(at)freenet(dot)co(dot)uk> wrote:
>
> Thanks, but I don't think thats what I want. Basically I need to get the row
> offset of a record (ie row) in a result set returned from the database. I
> know all the details of the row in question but when the search order changes
> I need to know the new index the row will have.
>
> In other words, I was hoping I would be able to select upto a particular row
> (not knowing its offset but knowing everything else about it) in a select
> query.
>
> Ideally I could do something like SELECT count(*) UNTIL col1=value1 &&
> col2=val2 etc....

Since you are ordering the data you can use where clauses with < (and/or >)
operators to stop counting at the desired row. For this to work the ordering
needs to be well defined. You can tack on the primary key to your list
of columns to order by to make the ordering well defined if it isn't
already.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Nicholas Allen 2003-02-12 19:55:21 Re: How do you select from a table until a condition is met?
Previous Message Nicholas Allen 2003-02-12 19:10:15 Re: How do you select from a table until a condition is met?