Adding columns to existing tables

From: John Pagakis <John(dot)Pagakis(at)DevelopOnline(dot)com>
To: "'pgsql-admin(at)postgresql(dot)org'" <pgsql-admin(at)postgresql(dot)org>
Subject: Adding columns to existing tables
Date: 2001-05-09 05:44:28
Message-ID: A04BDD2C264AD41181C000508BDCB72A71A0A4@usazdolexch0.developonline.home
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Content-Type Size
John Pagakis.vcf application/octet-stream 444 bytes

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Reiner Dassing 2001-05-09 09:43:10 Re: Restoring a pg_dump fails with
Previous Message Tim Boring 2001-05-08 22:15:40 Re: PGACCESS: error trying to connect...