Re: first question

From: Antonio Fiol Bonnín <fiol(at)w3ping(dot)com>
To: "Robert D(dot) M(dot) Smith" <robsm(at)calibredigital(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: first question
Date: 2001-11-21 18:36:52
Message-ID: 3BFBF444.1F3BA13B@w3ping.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)calibredigital(dot)com
> --------------------------------------------------------------------
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gurunandan R. Bhat 2001-11-21 18:39:37 Default conversion of type numeric to text in 7.1.3
Previous Message Thomas T. Thai 2001-11-21 18:18:08 Re: lingering processes