Re: select question - Mailing list pgsql-general

From Tom Lane
Subject Re: select question
Date
Msg-id 9503.965055321@sss.pgh.pa.us
Whole thread Raw
In response to Re: select question  (g <brian@wuwei.govshops.com>)
Responses Re: select question  (Felipe Alvarez Harnecker <felipe@qlsoft.cl>)
List pgsql-general
g <brian@wuwei.govshops.com> writes:
> Use the limit clause.
> SELECT message_text FROM messages ORDER BY creation_date LIMIT $limit,
> $offset.

> LIMIT 10, 0 gets you the first batch.
> LIMIT 10, 10 gets you the second batch.
> LIMIT 10, 20 gets you the third, etc.

BTW, a little tip that a number of people have gotten burnt by not
knowing: when you do this you *must* use an ORDER BY clause that's
strong enough to order the result rows completely.  Otherwise you
are asking for slices out of an undefined ordering of the rows.
You could get a different ordering on each request, leading to
inconsistent slices --- in other words, missing or repeated rows.

This does actually happen in Postgres 7.0, because the planner
optimizes queries with small limit+offset differently from those
without.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Rules & sequences
Next
From: ioseph@paolo.net
Date:
Subject: How I can undelete recodes?