Re: Dropping a column

From: Guy Fraser <guy(at)incentre(dot)net>
To: Patrick Aland <paland(at)stetson(dot)edu>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dropping a column
Date: 2001-01-23 04:23:54
Message-ID: 3A6D075A.3B277D18@incentre.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 problem I am running into is that some of the columns in my original table have certain attibutes (auto incrememnting, default values, 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2001-01-23 04:43:06 Re: User names
Previous Message Anand Raman 2001-01-23 04:18:44 Re: problem with copy