postgres date range based pre aggregation working