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

This is an updated pull request for https://github.com/TryGhost/Ghost/pull/1068, as requested in that PR.

All tests pass, though I haven't figured out how to explicitly run tests with Postgres yet.