Re: Unclear documentation (IMMUTABLE functions)

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniel Schreiber <daniel(dot)schreiber(at)s1999(dot)tu-chemnitz(dot)de>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Unclear documentation (IMMUTABLE functions)
Date: 2003-09-05 15:05:48
Message-ID: 15434.1062774348@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Daniel Schreiber <daniel(dot)schreiber(at)s1999(dot)tu-chemnitz(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Daniel Schreiber 2003-09-05 15:57:43 Re: Unclear documentation (IMMUTABLE functions)
Previous Message Stephan Szabo 2003-09-05 14:01:12 Re: Unclear documentation (IMMUTABLE functions)