Re: Count for pagination

Поиск
Список
Период
Сортировка
Искать
От
Michael C Rosenstein
Тема
Re: Count for pagination
Дата
Msg-id
4DA2F361.7040900@mdibl.org
Ответ на
Список
Дерево обсуждения
Count for pagination Jason Long <jason@octgsoftware.com>
Re: Count for pagination Stephen Frost <sfrost@snowman.net>
Re: Count for pagination Michael C Rosenstein <mcr@mdibl.org>
> Any suggestions on how to get the count of all records that could be
> returned

We use a window function to get the total # of records within each of 
our paginated queries:

SELECT
   ...
   ,COUNT(*) OVER() fullRowCount
FROM ...
WHERE ...
ORDER BY ...
LIMIT ... OFFSET ...;


While there is a cost to using the window  function, it's faster (for 
us) than two separate queries, and, more importantly, it's flexible 
enough to work in the 100s of different query contexts we have.

/mcr
В списке pgsql-general по дате отправления
От: Adrian Klaver
Дата:
От: Dmitriy Igrishin
Дата:
FAQ