fixed db sort for postgres