Re: trying to alter column

Lists: pgsql-admin
From: Aras Angelo <araskoktas(at)gmail(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: trying to alter column
Date: 2009-08-20 00:20:45
Message-ID: 5136d4130908191720q2bcd2cffo2db54da183d793f2@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

Im trying to alter a column type from character varying(8) to int.
All the values in the column are numbers but im getting this message

column "xxxxxx" cannot be cast to type integer

Dropping and readding the column is an option but downtime is very critical
to us, so i was wondering
if im doing something wrong and i can alter type somehow.


From: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>
To: Aras Angelo <araskoktas(at)gmail(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: trying to alter column
Date: 2009-08-20 02:44:06
Message-ID: dcc563d10908191944q79529767ic7c46ffa99f2675@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-admin

On Wed, Aug 19, 2009 at 6:20 PM, Aras Angelo<araskoktas(at)gmail(dot)com> wrote:
> Im trying to alter a column type from character varying(8) to int.
> All the values in the column are numbers but im getting this message
>
> column "xxxxxx" cannot be cast to type integer
>
> Dropping and readding the column is an option but downtime is very critical
> to us, so i was wondering
> if im doing something wrong and i can alter type somehow.

alter table xyz alter COLUMN i type int using i::int;

Note that this will fail if any of the entries in teh column i are not ints.