postgres: separate filter and paging queries

to get count to work