Re: how to get the total number of records in report

From: Greg Spiegelberg <gspiegelberg(at)gmail(dot)com>
To: AI Rumman <rummandba(at)gmail(dot)com>
Cc: Josh Kupershmidt <schmiddy(at)gmail(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: how to get the total number of records in report
Date: 2010-10-19 14:12:48
Message-ID: AANLkTimkTBF-xBfrxM5wNdxrEkP5wKkZGt2GLAynNC_e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Tue, Oct 19, 2010 at 1:18 AM, AI Rumman <rummandba(at)gmail(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Mladen Gogala 2010-10-19 14:22:42 Re: HashJoin order, hash the large or small table? Postgres likes to hash the big one, why?
Previous Message Jon Nelson 2010-10-19 13:38:30 Re: odd postgresql performance (excessive lseek)