Thomas Schoen <t(dot)schoen(at)vitrado(dot)de> writes:
> In my expectations the 2nd function call should not have added a new row
> to table "foo", beacause it was called with the same parameter and is
> immutable.
IMMUTABLE is a promise from you to the database (a promise which you
broke, in this case) ... not vice versa. There is no commitment to
avoid duplicate evaluations in all cases, and certainly not to do so
across multiple queries.
BTW, PG 8.0 will flat out reject this function, because it is violating
the requirement that immutable functions not have side-effects.
regards, tom lane