"Merlin Moncure" <mmoncure@gmail.com> writes:
> At present, immutable functions are only treated as constants during a
> query, which is what we want (no problems with prepare).
Uh, no, they'd be folded to constants at plan time, which is exactly
what Jeff doesn't want AFAICS.
The subselect trick is a bit of a hack, but at present it'll work to
guarantee that the function is called only once per plan execution.
(That's because we'll treat an "uncorrelated" subquery as an InitPlan
even if it contains volatile functions, which strictly speaking we
should not; but it's a sufficiently useful behavior that I wouldn't want
to get rid of it without providing a more principled substitute ...)
regards, tom lane