Re: Adding columns to existing tables

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: John Pagakis <John(dot)Pagakis(at)DevelopOnline(dot)com>
Cc: "'pgsql-admin(at)postgresql(dot)org'" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: Adding columns to existing tables
Date: 2001-05-09 16:00:30
Message-ID: Pine.BSF.4.21.0105090858120.86660-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message John Pagakis 2001-05-09 16:16:38 RE: Adding columns to existing tables
Previous Message Thomas Heller 2001-05-09 14:45:32 7.1 ... wtf?