Re: select question

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: select question
Дата
Msg-id 9503.965055321@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: select question  (g <brian@wuwei.govshops.com>)
Ответы Re: select question  (Felipe Alvarez Harnecker <felipe@qlsoft.cl>)
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Rules & sequences
Следующее
От: ioseph@paolo.net
Дата:
Сообщение: How I can undelete recodes?