Re: Does Postgresql have a similar pseudo-column "ROWNUM" as

From: Ragnar Hafstað <gnari(at)simnet(dot)is>
To: Alain <alainm(at)pobox(dot)com>
Cc: Sql-Postgre <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Does Postgresql have a similar pseudo-column "ROWNUM" as
Date: 2005-05-17 22:03:02
Message-ID: 1116367382.9362.11.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php pgsql-sql

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

In response to

Responses

Browse pgsql-php by date

  From Date Subject
Next Message PFC 2005-05-17 22:13:46 Re: Does Postgresql have a similar pseudo-column "ROWNUM" as
Previous Message Andrew Sullivan 2005-05-17 20:11:38 Re: Does Postgresql have a similar pseudo-column "ROWNUM" as

Browse pgsql-sql by date

  From Date Subject
Next Message PFC 2005-05-17 22:13:46 Re: Does Postgresql have a similar pseudo-column "ROWNUM" as
Previous Message Andrew Sullivan 2005-05-17 20:11:38 Re: Does Postgresql have a similar pseudo-column "ROWNUM" as