Re: Adding columns to existing tables - Mailing list pgsql-admin

From Stephan Szabo
Subject Re: Adding columns to existing tables
Date
Msg-id Pine.BSF.4.21.0105090858120.86660-100000@megazone23.bigpanda.com
Whole thread Raw
In response to Adding columns to existing tables  (John Pagakis <John.Pagakis@DevelopOnline.com>)
List pgsql-admin
On Tue, 8 May 2001, John Pagakis wrote:

> 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?

Unique is easy, you can create a unique index on the column which
is effectively what the unique constraint is doing behind the scenes.
Not null is harder, IIRC, you need to go and actually toggle
attnotnull in pg_attribute for the attribute.


pgsql-admin by date:

Previous
From: John Pagakis
Date:
Subject: RE: Adding columns to existing tables
Next
From: Grant
Date:
Subject: Cursor keys not working, repost.