views:

17

answers:

1

I am doing some standard paging in my application, returning 20 rows from the database at a time using PostgreSQL's standard OFFSET and LIMIT keywords. For instance, to get page 1:

SELECT stuff FROM table WHERE condition ORDER BY stuff OFFSET 0 LIMIT 20

It is a requirement of the application that we also show to the user the total number of records found (yes, I don't agree that they need to know this either, but it's not my job to argue!). So, obvious, I can get the total by issuing a separate query:

SELECT COUNT(*) FROM table WHERE condition

Obviously, if there are a large number of rows then this is not an optimal solution. I notice that MySQL has a very useful function called FOUND_ROWS() that does exactly what I am looking for:

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function%5Ffound-rows

Is there an equivalent in PostgreSQL?

Further, as a matter of interest, do any other RDBMs offer a similar feature?

+1  A: 

There is no equivalent. look at

http://archives.postgresql.org/pgsql-novice/2007-07/msg00108.php

Haim Evgi