Re: Alter column from text[] to uuid[] - Mailing list pgsql-general

From Tom Lane
Subject Re: Alter column from text[] to uuid[]
Date
Msg-id 25761.1434052615@sss.pgh.pa.us
Whole thread Raw
In response to Alter column from text[] to uuid[]  (Keith Rarick <kr@xph.us>)
Responses Re: Alter column from text[] to uuid[]
List pgsql-general
Keith Rarick <kr@xph.us> writes:
> I recently did the following:

> kr=# alter table t alter u type text[];
> ALTER TABLE
> Time: 5.513 ms

> Now I'd like to put it back the way it was, but my attempts didn't work:

> kr=# alter table t alter u type uuid[];
> ERROR:  column "u" cannot be cast automatically to type uuid[]
> HINT:  Specify a USING expression to perform the conversion.
> Time: 0.244 ms

It wants you to do this:

alter table t alter u type uuid[] using u::uuid[];

The original command worked without a USING because anything-to-text is
considered an allowable assignment coercion; but the other way around
requires an explicit cast.

> kr=# alter table t alter u type uuid[] using array_to_string(u,',');
> ERROR:  column "u" cannot be cast automatically to type uuid[]
> HINT:  Specify a USING expression to perform the conversion.
> Time: 0.321 ms

> (Interestingly, postgres seems to think I don't even have a USING clause
> here. Could there be some optimization that removed it?)

No, the error message is just worded carelessly; it's the same whether or
not you said USING.  Probably when there's a USING it needs to be worded
more like
ERROR:  result of USING clause cannot be cast automatically to type uuid[]

            regards, tom lane


pgsql-general by date:

Previous
From: Asma Riyaz
Date:
Subject: Re: GCC error and libmpfr.so.4 not found
Next
From: Asif Naeem
Date:
Subject: Re: GCC error and libmpfr.so.4 not found