Re: Count for pagination - Mailing list pgsql-general

From Michael C Rosenstein
Subject Re: Count for pagination
Date
Msg-id 4DA2F361.7040900@mdibl.org
Whole thread Raw
In response to Count for pagination  (Jason Long <jason@octgsoftware.com>)
List pgsql-general
> 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 by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Global Variables in plpgsql
Next
From: Dmitriy Igrishin
Date:
Subject: Re: Global Variables in plpgsql