I wrote:
> Attached is a draft patch against HEAD for this.
I've finished back-porting this. I'm not going to commit it until 9.2.0
is definitely gold, but attached is the 9.1 version of the patch, if
you'd like to try it and verify that it fixes your original problem.
regards, tom lane