X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7F1B9475BA1 for ; Wed, 12 Feb 2003 14:12:29 -0500 (EST) Received: from localhost.localdomain (A073e.pppool.de [213.6.7.62]) by postgresql.org (Postfix) with ESMTP id 69BFA475B99 for ; Wed, 12 Feb 2003 14:12:27 -0500 (EST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by localhost.localdomain (8.11.6/8.11.6) with ESMTP id h1CJAFa04999; Wed, 12 Feb 2003 20:10:17 +0100 Content-Type: text/plain; charset="iso-8859-1" From: Nicholas Allen To: Dmitry Tkach Subject: Re: How do you select from a table until a condition is met? Date: Wed, 12 Feb 2003 20:10:15 +0100 User-Agent: KMail/1.4.1 References: <200302121910.38232.nallen@freenet.co.uk> <3E4AB0E7.3010101@openratings.com> In-Reply-To: <3E4AB0E7.3010101@openratings.com> Cc: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200302122010.15297.nallen@freenet.co.uk> X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/246 X-Sequence-Number: 11644 Thanks, but I don't think thats what I want. Basically I need to get the ro= w=20 offset of a record (ie row) in a result set returned from the database. I= =20 know all the details of the row in question but when the search order chang= es=20 I need to know the new index the row will have.=20 In other words, I was hoping I would be able to select upto a particular ro= w=20 (not knowing its offset but knowing everything else about it) in a select= =20 query.=20 Ideally I could do something like SELECT count(*) UNTIL col1=3Dvalue1 &&=20 col2=3Dval2 etc.... Of course there is no UNTIL in a select statement just a WHERE clause. I know I didn't explain that very well! Well I hope you can still help? On Wednesday 12 Feb 2003 9:39 pm, Dmitry Tkach wrote: > select * from table order by x limit 10; -- get first 10 > select * from table order by x offset 10 limit 10; -- get 10 - 20 > select * from table order by x offset 40 limit 10; -- get 40-50 > > OR > > begin; > declare mycursor cursor for select * from table order by x; > fetch 10 from mycursor; -- get first 10 > fetch 10 from mycursor; -- get 10-20 > move 20 in mycursor; > fetch 10 from mycursor; -- get 40-50 > > > > Is that what you are talking about? > > Dima > > Nicholas Allen wrote: > > Hi, > > > > I am hoping that someone can help me with a problem I have. I would like > > to=3D be=3D20 > > able to perform a SELECT query to select values from a table upto a > > certain=3D =3D20 > > row. The select may be ordered on a number of items. Is it possible to > > do=3D =3D20 > > this and how should I do it? > > > > The reason I need this is because I have created a virtual table browser > > cl=3D ass=3D20 > > that performs SQL queries to get the sections of the table the user is= =3D20 > > interested in. This way I don't load the whole table onto the client > > side. =3D If=3D20 > > the user changes the sort ordering I want to determine the row index th= at > > w=3D as=3D20 > > previously selected and scroll to that location. > > > > Any help would be very much appreciated. > > > > Thanks in advance, > > > > Nicholas Allen > > > > ---------------------------(end of broadcast)--------------------------- > > TIP 3: if posting/reading through Usenet, please send an appropriate > > subscribe-nomail command to majordomo@postgresql.org so that your > > message can get through to the mailing list cleanly