Re: Simple SQL Question

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Andras Kutrovics <n-drew(at)freemail(dot)hu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Simple SQL Question
Date: 2004-11-05 18:09:55
Message-ID: 418BC1F3.7080205@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Hi All!
>
> In one of my application, I would like to implement incremental
> fetching. The problem is that I would like to run it
> from a stateless application server, so I have to tell where
> to begin fetching data. It is simple for a table which has single column
> primary key, but causes difficulties (at least for me) in
> a more-column primary key..
>
> Let say I have a table wich has the primary key: itemkey,location
>
> table1
> ------
> itemkey
> location
> ...
> --------
>
>
> select * from table1 LIMIT x
>
> gives me the first x row of the result.
> After that, I save the last value, and next time, I adjust
> the query as
>
> select * from table1 where itemkey>:lastvalue LIMIT x

Why do you complicate it so much? Everything you need is:

select * from table1 LIMIT x
select * from table1 LIMIT x OFFSET x
select * from table1 LIMIT x OFFSET 2*x

Remember to sort rows before using limit/offset.

Regards,
Tomasz Myrta

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Ian Barwick 2004-11-05 19:53:00 Re: oracle v$session equivalent in postgresql
Previous Message Franco Bruno Borghesi 2004-11-05 18:09:20 Re: Simple SQL Question