| From: | Klein Balázs <Balazs(dot)Klein(at)axelero(dot)hu> |
|---|---|
| To: | <pgsql-general(at)postgresql(dot)org> |
| Subject: | alter column datatype with cast |
| Date: | 2005-12-29 20:46:10 |
| Message-ID: | 20051229204617.0FBA33E515C@graveyard.mail.t-online.hu |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
I had to change the datatype of a column from text to integer. The column
contained integers (obviously stored as text).
When I tried to change the datatype of the column I got an error message
saying that the column can not be cast to integer:
Operation : ALTER TABLE "public"."subjectgroupcondition" ALTER COLUMN
"param1" TYPE INTEGER
Result : "ERROR: column "param1" cannot be cast to type
"pg_catalog.int4""
However when I created an other integer column in the table and updated it
from the text column there was no problem casting the data:
Operation : UPDATE public.subjectgroupcondition SET param2 = cast(param1 as
integer);
Result : "OK."
Since pg knows that it should cast the data and it can cast it I think I
should have been able to change the datatype in the first instance. Maybe
this behaviour has a good reason but I don't know what it is.
Regards,
SWK
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Joshua Kramer | 2005-12-29 21:10:01 | Stored Procedure: PL/Perl or PL/SQL? |
| Previous Message | Guy Rouillier | 2005-12-29 19:33:10 | Re: [Bulk] Re: Final stored procedure question, for now anyway |