Re: Changed a column type from "integer" to varchar

From: Arthur Hoogervorst <arthur(dot)hoogervorst(at)gmail(dot)com>
To: Ying Lu <ying_lu(at)cs(dot)concordia(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Changed a column type from "integer" to varchar
Date: 2004-09-14 20:39:10
Message-ID: ff60f9b30409141339123daecd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

If you're using 7.4 or below (I'm not sure if 7.5 is able to do this),
you'll end up writing the data first to a temporary table, as in (for
example):

SELECT * INTO TEMPORARY MyTable
FROM yourtable;

DROP TABLE yourtable;

CREATE TABLE yourtable (
/* with varchar stuff */
) WITH OIDS;

INSERT into yourtable
(
your field list
)
SELECT
cast(anumber as varchar(20)),
etc,
from MyTable;

Drop MyTable;

Regards,

Arthur

On Tue, 14 Sep 2004 16:14:33 -0400, Ying Lu <ying_lu(at)cs(dot)concordia(dot)ca> wrote:
> Hi,
>
> I have a question about alter a column's type in a postgreSQL table.
>
> For example, I have 10, 000 records in a table name "test", I'd like to
> change column "machineID" type from integer to varchar. I am looking for
> something like:
>
> alter table test alter column machineID ... ... varchar
>
> Thanks in advance,
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faqs/FAQ.html
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2004-09-14 20:45:53 Re: Changed a column type from "integer" to varchar
Previous Message Joshua D. Drake 2004-09-14 20:33:32 Re: Changed a column type from "integer" to varchar