"Fernando Hevia" <fhevia@ip-tel.com.ar> writes:
> -- In this case function test is called only once:
> pg=# select res[0] as sum, res[1] as prod, res[2] as dif from
> pg-# (select (test(1, 2))::integer[] as res) t ;
That's an implementation artifact, not a guaranteed behavior;
if you change the example a bit you'll find multiple calls
happening.
(In recent releases you'd actually have a better chance of
not having multiple calls if you'd declared it volatile
instead of immutable.)
regards, tom lane