Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-admin by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group