Fixed postgres sorting