X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 9B99752813 for ; Tue, 17 May 2005 19:03:12 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03704-09 for ; Tue, 17 May 2005 22:03:03 +0000 (GMT) Received: from quasar.skima.is (quasar.skima.is [212.30.200.205]) by svr1.postgresql.org (Postfix) with ESMTP id 3B6E652833 for ; Tue, 17 May 2005 19:03:01 -0300 (ADT) Received: from gnari ([85.220.28.44] [85.220.28.44]) by quasar.skima.is with ESMTP; Tue, 17 May 2005 22:03:01 Z Subject: Re: Does Postgresql have a similar pseudo-column "ROWNUM" as From: Ragnar =?ISO-8859-1?Q?Hafsta=F0?= To: Alain Cc: Sql-Postgre In-Reply-To: <428A3B54.4070902@pobox.com> References: <20050517170636.GC12405@phlogiston.dyndns.org> <428A2E81.2060501@pobox.com> <1116353539.26520.5.camel@localhost.localdomain> <428A3B54.4070902@pobox.com> Content-Type: text/plain Date: Tue, 17 May 2005 22:03:02 +0000 Message-Id: <1116367382.9362.11.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.002 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/142 X-Sequence-Number: 21455 On Tue, 2005-05-17 at 15:43 -0300, Alain wrote: > [how to solve the get next 100 records problem] I am assuming this is for a web like interface, in other words that cursors are not applicable > > [me] > > if you are ordering by a unique key, you can use the key value > > in a WHERE clause. > > > > select ... where ukey>? order by ukey limit 100 offset 100; > > > > (the ? is placeholder for the last value of ukey returned > > from previous select) > > I tried that. It does not work in the generic case: 6 MegaRec, telephone > listing, alphabetical order. The problem is that somewhere there is a > single user with too many entries (over 1000). I even tried to filter > the repetitions, but somewhere I get stuck if one guy has too mny > entries (one for each phone number). > > I tried using both the name and the primary key (with a combined index), > to get faster to the record I want, but I was not sucessfull in building > a where clause. lets say pkey is your primary key and skey is your sort key, and there exists an index on (skey,pkey) your first select is select ... from tab ORDER by skey,pkey LIMIT 100; your subsequent selects are select ... from tab WHERE skey>skey_last OR (skey=skey_last AND pkey>pkey_last) ORDER BY skey,pkey LIMIT 100 OFFSET 100; > I would appreciate any help, in fact this is my primary reason for > joining this list ;-) gnari