Why is cast array integer[] <--> text[] is not immutable.

Started by Phil Coulingover 14 years ago4 messagesgeneral
Jump to latest
#1Phil Couling
couling@gmail.com

Hi

I'm struggling to understand why this casts is not immutable:

integer[]::text[]
text[]::integer[]

The following are all immutable:

integer::text
text::integer
integer[]::float[]
integer::float

I hit on this while trying to make a gin index which cast from one to the other.

Why does the encapsulation of an array suddenly make this not immutable?

Thanks

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Phil Couling (#1)
Re: Why is cast array integer[] <--> text[] is not immutable.

Phil Couling <couling@gmail.com> writes:

I'm struggling to understand why this casts is not immutable:

integer[]::text[]
text[]::integer[]

Because it's implemented via array_out/array_in rather than any more
direct method, and those are marked stable because they potentially
invoke non-immutable element I/O functions.

regards, tom lane

#3Phil Couling
couling@gmail.com
In reply to: Tom Lane (#2)
Re: Why is cast array integer[] <--> text[] is not immutable.

Thanks

I'm having trouble finding any reference to array_out and array_in in
the documentation.

Is there a way to set a different cast for an array?

Regards

Show quoted text

On 9 December 2011 15:09, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Phil Couling <couling@gmail.com> writes:

I'm struggling to understand why this casts is not immutable:

integer[]::text[]
text[]::integer[]

Because it's implemented via array_out/array_in rather than any more
direct method, and those are marked stable because they potentially
invoke non-immutable element I/O functions.

                       regards, tom lane

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Phil Couling (#3)
Re: Why is cast array integer[] <--> text[] is not immutable.

Phil Couling <couling@gmail.com> writes:

Is there a way to set a different cast for an array?

I think it should work to declare a cast explicitly for the particular
case.

regards, tom lane