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.