Thread: Is it possible to drop a column?

Is it possible to drop a column?

From
"sim"
Date:
Hello,

Is it possible to drop a column?

Thanks.

Re: [GENERAL] Is it possible to drop a column?

From
"Jose' Soares"
Date:
The SQL command is:

   ALTER TABLE table DROP [COLUMN] column { RESTRICT | CASCADE }

but PostgreSQL hasn't this feature yet.

Currently, to remove an existing column the table must be recreated
and reloaded. For example, if want to remove field "address" from table
"distributors"
you have to...


distributors:
----------------------
field    type
----------------------
did    DECIMAL(3)
name    VARCHAR(40)
address    VARCHAR(40)
----------------------


          CREATE TABLE temp AS SELECT did, city FROM distributors;
          DROP TABLE distributors;
          CREATE TABLE distributors (
               did      DECIMAL(3)  DEFAULT 1,
               name     VARCHAR(40) NOT NULL,
               );

          INSERT INTO distributors SELECT * FROM temp;
          DROP TABLE temp;


sim wrote:
>
> Hello,
>
> Is it possible to drop a column?
>
> Thanks.


Jose'