Gerhard Heift <ml-postgresql-20081012-3518@gheift.de> writes:
> The function is called for every row in the table if it is stable or
> volatile and only once if it is immutable?
Yes, possibly.
> I thought it had to be called only once, if it is stable.
No. Stable means that it is *okay* to call it only once per query,
not that that is *guaranteed* to happen. (What it really does is give
the planner license to use an indexscan on a condition involving the
function --- an indexscan's comparison value is evaluated just once,
so it would give the wrong answers for a non-stable function.)
regards, tom lane