[Gllug] POSTGRES: Change type of column or delete

Vincent AE Scott gllug at codex.net
Mon Oct 22 21:13:25 UTC 2001


John Edwards(john_ed at cornerstonelinux.co.uk)@Mon, Oct 22, 2001 at 09:56:01PM +0100:
> 
> Hi
> Anyone know to change the type of a column in postgres ? Or failing that 
> even how to delete a column ?
> 
> "ALTER TABLE" only seems to be able to add and rename them. I've tried 
> the postgresql site and google, but can't find anything useful.

postgres does not support teh syntax 'alter table <table> drop column <column>


you must create a temp table, select into it, drop the original, create it again and then select the temp data back into it...

from the help files:


Removes a column from a table. Currently, to remove an existing column the table must be recreated and reloaded:

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;
       



-- 


PGP key:  http://codex.net/pgp/pgp.asc

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list