Jeff Davis <pgsql@j-davis.com> writes:
> On Tue, 2010-07-20 at 11:31 +0200, Pavel Stehule wrote:
>> I am working on to_array, to_string functions and I am looking on
>> string_to_array function. I am surprised so this function is marked as
>> immutable
> What's wrong with that? "current_date" is the part that's changing, and
> it's being passed as an argument to the function. If the argument
> changes, an immutable function can return a different result.
string_to_array() seems fine to me: it's a predictable transformation
from text to text. However, I think that there really is an issue with
array_to_string(), because that takes an anyarray and invokes the array
element's type output function. Type output functions are not
necessarily immutable, and if the input is of a type where that's not
true, then the array_to_string() transformation isn't immutable either.
An example is that date's output function produces different results
depending on datestyle.
I can't remember offhand whether there are any volatile type output
functions, but if there were we'd really need to mark array_to_string()
as volatile. That would be unpleasant for performance though. I'd
rather compromise on stable. Thoughts?
regards, tom lane