Re: ALTERING A TABLE - Mailing list pgsql-general

From Ross J. Reedstrom
Subject Re: ALTERING A TABLE
Date
Msg-id 20000601141105.A20587@rice.edu
Whole thread Raw
In response to Re: ALTERING A TABLE  (Steve Wampler <swampler@noao.edu>)
List pgsql-general
On Thu, Jun 01, 2000 at 11:00:09AM -0700, Steve Wampler wrote:
> Ron Peterson wrote:
> >
> >
> > You can't use ALTER TABLE to change a field's data description.  You'll
> > have to make a new table.  Then use SELECT INTO to move your data.  Then
> > DROP TABLE oldtable.  Then ALTER TABLE tablename RENAME TO newname.
>
> Would this really work?  According to the docs, SELECT INTO creates a
> new table (which must not yet exist).  So this new table
> would have the same field data descriptions as the original, right?
>
> Is the documentation wrong?

Document's right, Ron mis-spoke (mis-typed?) That should be "INSERT INTO
... SELECT ... FROM"

The tricky part is doing the select in such a way that the data gets
converted on the way into the new table. This shouldn't be a problem
for text to text, but if you where changing the type of a column, you'd
need to cast it on the way.

Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005

pgsql-general by date:

Previous
From: "Diego Schvartzman"
Date:
Subject: Re: CREATE USER
Next
From: Bruce Momjian
Date:
Subject: Re: btree index and max()