Adding columns to existing tables - Mailing list pgsql-admin

From John Pagakis
Subject Adding columns to existing tables
Date
Msg-id A04BDD2C264AD41181C000508BDCB72A71A0A4@usazdolexch0.developonline.home
Whole thread Raw
Responses Re: Adding columns to existing tables  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
List pgsql-admin
I have a table - suppose it is called company:

CREATE TABLE ( company_id char(36) NOT NULL UNIQUE PRIMARY KEY,
            .
            .
            .
        );

I want to add the following field:
    company_nemonic char( 3 ) NOT NULL UNIQUE

Well, ALTER TABLE only gets me part of the way there.  While this code
successfully adds the table:
    ALTER TABLE
        company
    ADD COLUMN
        company_nemonic char( 3 ) NOT NULL UNIQUE;

the constraints are ignored.


Is there an easy way to add the constraints after the fact?

I have resorted to creating a company_temp table, insert into company_temp
selecting from company, dropping company and then renaming company_temp to
company.  This works, but causes another problem.  The index for the unique
key company_temp_pkey does not get renamed with the table.  This means if I
ever want to do something like this again, the create of company_temp will
fail because company_temp_pkey already exists.

Any help would be much appreciated.
_______________________________________
John Pagakis
DevelopOnline.com
480.377.6828
 <<John Pagakis.vcf>>

Attachment

pgsql-admin by date:

Previous
From: Tim Boring
Date:
Subject: Re: PGACCESS: error trying to connect...
Next
From: Reiner Dassing
Date:
Subject: Re: Restoring a pg_dump fails with