I wrote:
> Just for fun, I hacked together a first cut at this.
Oh, just for the archives: I forgot about not suppressing volatile
expressions --- checking that would increase the cost of this
significantly, though it's only another line or two.
regards, tom lane