SQL_CALC_FOUND_ROWS (kind of) for postgres

When I switched from MySQL to PostgreSQL, one of the things I missed the most was the ease of paging using SQLCALCFOUNDROWS and SELECT FOUNDROWS() afterwards. One of the places I use it heavily is in my Table class, which generates, sortable, filterable and paged HTML table based on an SQL Query. The tough spot was to get all the records' count, without supplying second query.

I found the solution in ADODB's Pager class and it is the following:

Given the query: SQL, execute the following query:

SELECT Count(*) FROM ([SQL]) AS foo;

I know it's not as easy as SQLCALCFOUND_ROWS but it works;

Comments

comments powered by Disqus