Re: How to change data type in column ?

Поиск
Список
Период
Сортировка
От
Тема Re: How to change data type in column ?
Дата
Msg-id 1338.219.65.253.230.1050428701.squirrel@mail.trade-india.com
обсуждение исходный текст
Ответ на Re: How to change data type in column ?  ("scott.marlowe" <scott.marlowe@ihs.com>)
Список 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@postgresql.org)



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


В списке pgsql-general по дате отправления:

Предыдущее
От: Guy Fraser
Дата:
Сообщение: Re: Arrays ... need clarification....
Следующее
От: Guy Fraser
Дата:
Сообщение: Re: Case sensitive order by