Обсуждение: first question

Поиск
Список
Период
Сортировка

first question

От
"Robert D. M. Smith"
Дата:
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
--------------------------------------------------------------------

Re: first question

От
Antonio Fiol Bonnín
Дата:
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