Re: Dropping a column - Mailing list pgsql-general

From Guy Fraser
Subject Re: Dropping a column
Date
Msg-id 3A6D075A.3B277D18@incentre.net
Whole thread Raw
In response to Dropping a column  (Patrick Aland <paland@stetson.edu>)
List pgsql-general
Patrick Aland wrote:
>
> I know how to drop a column from a table by selecting into a new table the columns I want to keep. However the
problemI am running into is that some of the columns in my original table have certain attibutes (auto incrememnting,
defaultvalues, etc) however the method of: 
>
> SELECT id,name,description INTO TABLE temp FROM origtable;
> DROP TABLE origtable;
> ALTER TABLE temp RENAME TO origtable;
>
> Preserves my data but not the extra column information (at least according to a \d tablename)
>
> Anyone know if it is possible to do this?
>
> Thanks.
>
...snip...

Hi

You can create a new table then :

INSERT INTO newtable (id,name,description) SELECT id,name,description
from origtable;

DROP TABLE origtable;

ALTER TABLE newtable RENAME TO origtable;

That has worked for me in the past, when I noticed this problem.

Guy

pgsql-general by date:

Previous
From: "Prasanth Kumar"
Date:
Subject: Re: Data entry screen building utilities
Next
From: Bruce Momjian
Date:
Subject: Re: syntax of outer join in 7.1devel