Sliding sum aggregate function for postgresql