Re: Unclear documentation (IMMUTABLE functions) - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Unclear documentation (IMMUTABLE functions)
Date
Msg-id 15434.1062774348@sss.pgh.pa.us
Whole thread Raw
In response to Unclear documentation (IMMUTABLE functions)  (Daniel Schreiber <daniel.schreiber@s1999.tu-chemnitz.de>)
Responses Re: Unclear documentation (IMMUTABLE functions)
List pgsql-bugs
Daniel Schreiber <daniel.schreiber@s1999.tu-chemnitz.de> writes:
> A question on IMMUTABLE functions: do they only have to return the same value
> during a session/connection or during the databse server's lifetime?

Lifetime, I'd say, since among other things IMMUTABLE is considered to
mean that it's okay to build an index on the function's results.

Of course, you can cheat: the system makes no attempt to verify whether
a function that you say is IMMUTABLE really is.  There are cases where
it's useful to lie about the mutability property of a function.  What
you are basically controlling here is whether the planner will deem it
safe to pre-evaluate a call of the function.  Unless you actually do
build a functional index using a function, I doubt it could matter
whether the results change from one session to the next.

> I wrote a function that uses the CURRENT_USER session variable, and for my
> current usage it is very important, that it returns a different value for
> each database connection.

CURRENT_USER is marked STABLE, not IMMUTABLE.  Not sure what your point
is here.

            regards, tom lane

pgsql-bugs by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: Unclear documentation (IMMUTABLE functions)
Next
From: Daniel Schreiber
Date:
Subject: Re: Unclear documentation (IMMUTABLE functions)