Re: how to get the total number of records in report - Mailing list pgsql-performance

From Greg Spiegelberg
Subject Re: how to get the total number of records in report
Date
Msg-id AANLkTimkTBF-xBfrxM5wNdxrEkP5wKkZGt2GLAynNC_e@mail.gmail.com
Whole thread Raw
In response to Re: how to get the total number of records in report  (AI Rumman <rummandba@gmail.com>)
List pgsql-performance
On Tue, Oct 19, 2010 at 1:18 AM, AI Rumman <rummandba@gmail.com> wrote:
Not actualy. I used pagination with limit clause in details query and I need the total number of records in the detail query.


Can you use a cursor?  Roughly...

BEGIN;
DECLARE x CURSOR FOR SELECT * FROM crm;
MOVE FORWARD ALL IN x;
MOVE BACKWARD ALL IN x;
MOVE FORWARD 100 IN x;
FETCH FORWARD 100 FROM x;
CLOSE x;
COMMIT;

Your  application would need to get the actual text result from the "MOVE FORWARD ALL IN x;" statement to know the total number of records from your SELECT.  After that, do your pagination via the "MOVE FORWARD 100 IN x;" and "FETCH FORWARD 100 FROM x;" statements.

HTH.
Greg

pgsql-performance by date:

Previous
From: Jon Nelson
Date:
Subject: Re: odd postgresql performance (excessive lseek)
Next
From: Mladen Gogala
Date:
Subject: Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?