Re: why VOLATILE attribute is required? - Mailing list pgsql-general

From Szymon Guz
Subject Re: why VOLATILE attribute is required?
Date
Msg-id CAFjNrYvbNGf2_k63H-HcY2QNA4JFd6RTjRqKPg_j3917a9ZboA@mail.gmail.com
Whole thread Raw
In response to Re: why VOLATILE attribute is required?  (Rafal Pietrak <rafal@zorro.isa-geek.com>)
Responses Re: why VOLATILE attribute is required?
List pgsql-general


On 22 September 2011 16:29, Rafal Pietrak <rafal@zorro.isa-geek.com> wrote:
On Thu, 2011-09-22 at 07:50 -0500, Merlin Moncure wrote:
> On Thu, Sep 22, 2011 at 5:28 AM, Rafal Pietrak <rafal@zorro.isa-geek.com> wrote:
>
> if you change the state of the database, including (and especially)
> system catalogs, your function is volatile, period.

Hmmm. To quote from the online documentation:

"VOLATILE indicates that the function value can change even within a
single table scan"

this funciton return value does not change. Further we read:

"any function that has side-effects must be classified volatile, even if
its result is quite predictable, to prevent calls from being optimized
away;"

Well. In this caase, I'd like it being optimised away. This is the
expected result. And the above documentation fragment states it as only
a precausion, not an ERROR.

Are there other reasons for that ERROR (e.g. not a warrning)?

Yes, the reason is that caching that function could be a problem.

And why do you want to optimize that? 
Does it take too much time, or do you want to call that thousands of times?
Have you checked how much the function lasts?
 


regards
Szymon

pgsql-general by date:

Previous
From: Eric Ridge
Date:
Subject: OS X 10.7, psql, and tab completion?
Next
From: Jeff Adams
Date:
Subject: Sending Results From One Function As Input into Another Function