Glyn Astill <glynastill(at)yahoo(dot)co(dot)uk> writes:
> Does anyone know how I can change what I'm doing to get pgsql to pick a better plan?
You've provided no evidence that this is a bad plan.
In particular, the plan you seem to think would be better would involve
an estimated 153 iterations of the cost-15071 hash aggregation, which
simple arithmetic shows is more expensive than the plan it did choose.
regards, tom lane