Thread: A question of volatility

A question of volatility

From
Dean Rasheed
Date:
This is probably a really trivial question, so hopefully this is the place to ask it.

If I have a couple of STABLE functions f1() and f2(), and then I write a third function f3()
which does nothing other than call f1() and f2(), is it safe to mark f(3) as IMMUTABLE?

Thanks,

Dean

_________________________________________________________________
Feel like a local wherever you go.
http://www.backofmyhand.com

Re: A question of volatility

From
Michael Glaesemann
Date:
On Nov 24, 2007, at 8:00 , Dean Rasheed wrote:

> If I have a couple of STABLE functions f1() and f2(), and then I
> write a third function f3()
> which does nothing other than call f1() and f2(), is it safe to
> mark f(3) as IMMUTABLE?

No. Why would calling two STABLE functions be IMMUTABLE? If it's
going to be anything other than STABLE, it would be VOLATILE.

Michael Glaesemann
grzm seespotcode net



Re: A question of volatility

From
Dean Rasheed
Date:
>> If I have a couple of STABLE functions f1() and f2(), and then I
>> write a third function f3()
>> which does nothing other than call f1() and f2(), is it safe to
>> mark f(3) as IMMUTABLE?
>
> No. Why would calling two STABLE functions be IMMUTABLE? If it's
> going to be anything other than STABLE, it would be VOLATILE.
>
> Michael Glaesemann
> grzm seespotcode net
>

Thanks for that. I was afraid it would sound like a stupid question,
which is why I used the "novice" mailing list. I've only been using
Postgres a few weeks.

My reason for asking is that some languages maintain a dependency tree
of functions, and so could in theory do something clever with
dependent functions - such as distinguishing between *declared* and
*derived* volatility.

Example scenario - suppose I wrote an IMMUTABLE function calc_vat()
which multiplied its input by 0.175 (the VAT rate here in the UK) and
a whole library of other functions based on that. Then, some time
later, I decided that I would quite like to be able to vary the VAT
rate, so I made my calc_vat() function read from a table, making it
STABLE. What you're saying is that I would have to search through all
the functions in the database finding any that call calc_vat(), and
any that call those functions, and so on, making sure that they are
all at least STABLE.

Is there anything available that would help with that process? In
Oracle's PL/SQL, for example, after changing the function, I would
select from USER_OBJECTS, to find any functions which had been marked
invalid by my change.

Cheers, Dean.

_________________________________________________________________
The next generation of MSN Hotmail has arrived - Windows Live Hotmail
http://www.newhotmail.co.uk

Re: A question of volatility

From
Tom Lane
Date:
Dean Rasheed <dean_rasheed@hotmail.com> writes:
> My reason for asking is that some languages maintain a dependency tree
> of functions, and so could in theory do something clever with
> dependent functions - such as distinguishing between *declared* and
> *derived* volatility.

That might be possible in a system that only supports statically
analyzable functions, but Postgres is not such a system.  Consider
EXECUTE in plpgsql, or anything at all in plperl or pltcl.

            regards, tom lane