Re: first question - Mailing list pgsql-general

From Antonio Fiol Bonnín
Subject Re: first question
Date
Msg-id 3BFBF444.1F3BA13B@w3ping.com
Whole thread Raw
In response to first question  ("Robert D. M. Smith" <robsm@calibredigital.com>)
List pgsql-general
I think of the following (maybe inefficient) way:

CREATE TABLE tempName ( ... , myColumn newType, ... );
INSERT INTO tempName SELECT * from myTable;

Verify that everything is OK and the content went correctly into the new
column. If not, you may need to use SELECT column1, column2, ...
myColumn::newType, ... columnN FROM myTable

If everything is OK by now:

DROP TABLE myTable;
ALTER TABLE tempName RENAME TO myTable;

Create any indexes that were present on myTable before dropping it, as they
are destroyed along with it.

Good luck!

Antonio


"Robert D. M. Smith" wrote:

> Hello to all!
>
> I'm new to this list and to postgres so my terminology may be incorrect.
>
> Is there a way to change the datatype of a column? For example, I have a
> column that was originally setup as int4 type & now I want it to be
> text.
>
> Is there a simple way or would I have to delete the column and re-enter
> with new type?
> Any help would be appreciated. Thanks!
>
> --
>    Rob
>
> --------------------------------------------------------------------
> Robert D.M. Smith
> Animation Director
> Calibre Digital Pictures
> 416.531.8383 x3787
> robsm@calibredigital.com
> --------------------------------------------------------------------
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster


pgsql-general by date:

Previous
From: Alex Avriette
Date:
Subject: Re: Performance: Perl-DBI vs. PG Stored Procedures
Next
From: "Gurunandan R. Bhat"
Date:
Subject: Default conversion of type numeric to text in 7.1.3