Re: How to change data type in column ?

From: <mallah(at)trade-india(dot)com>
To: <scott(dot)marlowe(at)ihs(dot)com>
Cc: <Vitali(dot)Djatsuk(at)MicroLink(dot)ee>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to change data type in column ?
Date: 2003-04-15 17:45:01
Message-ID: 1338.219.65.253.230.1050428701.squirrel@mail.trade-india.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> On Tue, 15 Apr 2003, Vitali Djatsuk wrote:
>
>>
>> Hi,
>>
>> How can I change a data type in column ?
>
> There are a lot of issues involved in changing the type. I.e. what should the database do to
> "coerce" the data from one type to another that's already in the table. should the misformed
> data in the input be simply dropped and a null inserted, what if it's not null and doesn't
> fit, do we toss the row? not convert?
> The best way to get around these problems is to select the fields into a new table and coerce
> the type as you do it. That way, you can see where you're going before you get there.
>
> create table test (name text, id int, balance numeric (12,2), num float); insert some data...
> select name, id, balance::float, num::numeric(12,2) into newtable;
>
> Now you can check newtable, and if it's right you can then delete the old table and rename
> newtable in its place.

Instead of deleting the table
Why not add a new column of the required type , update it with the values
from old column , drop the old column and rename the new col to the old col .

Considering the fact that he already got too many references it may be easier
to avoid drop the table altogether.

regds
mallah.

>
>
> ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off
> all lists at once with the unregister command
> (send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

-----------------------------------------
Get your free web based email at trade-india.com.
"India's Leading B2B eMarketplace.!"
http://www.trade-india.com/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2003-04-15 17:58:01 Re: Backpatch FK changes to 7.3 and 7.2?
Previous Message Guy Fraser 2003-04-15 17:40:49 Re: Arrays ... need clarification....