Re: How to change data type in column ? - Mailing list pgsql-general

From scott.marlowe
Subject Re: How to change data type in column ?
Date
Msg-id Pine.LNX.4.33.0304151027230.18680-100000@css120.ihs.com
Whole thread Raw
In response to How to change data type in column ?  ("Vitali Djatsuk" <Vitali.Djatsuk@MicroLink.ee>)
Responses Re: How to change data type in column ?  (<mallah@trade-india.com>)
List 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.


pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: [PERFORM] Yet Another (Simple) Case of Index not used
Next
From: Joe Conway
Date:
Subject: Re: Appending to an array