Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
> this is not bug - it is consequence of plan cache
FWIW, there is documentation of this issue near the end of
http://www.postgresql.org/docs/9.1/static/plpgsql-implementation.html#PLPGSQL-PLAN-CACHING
This exact case isn't covered in the examples, but the point is that the
expression 'now'::timestamp will get folded to a timestamp constant during
planning, and then not replanned later. As Pavel says, it's a lot safer
to use one of the variants of the now() function.
regards, tom lane