Fix #896 - work around errors in pagination under Postgresql.
Merge pull request #1088 from jacobian/postgres-fix

Fix #896 - work around errors in pagination under Postgresql.