pg aggregate support - refactor to be more type safe