From: Vivek Khera <khera@kcilink.com>
To: pgsql-sql@postgresql.org
Subject: adding column with not null constraint
Date: 18 Oct 2002 16:12:01 -0400
Message-ID: <x7u1jjmrqm.fsf@onceler.kciLink.com> (raw)
I'm looking to add a column to my database with not null and a default
value:
vk=> alter table msg_owner add column user_optional_fields varchar(255) NOT NULL default '';
ERROR: Adding columns with defaults is not implemented.
Add the column, then use ALTER TABLE SET DEFAULT.
vk=> alter table msg_owner add column user_optional_fields varchar(255) NOT NULL ;
ERROR: Adding NOT NULL columns is not implemented.
Add the column, then use ALTER TABLE ADD CONSTRAINT.
Ok, so we can succeed with this:
ALTER TABLE msg_owner ADD COLUMN user_optional_fields VARCHAR(255);
ALTER TABLE msg_owner ALTER user_optional_fields SET DEFAULT '';
UPDATE msg_owner SET user_optional_fields = '';
Now my problem is I cannot find any syntax for ALTER TABLE ADD
CONSTRAINT to put a NOT NULL constraint on a column. Can someone help
me here?
I'm using Postgres 7.2.1 on FreeBSD 4.6.
Thanks.
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Vivek Khera, Ph.D. Khera Communications, Inc.
Internet: khera@kciLink.com Rockville, MD +1-240-453-8497
AIM: vivekkhera Y!: vivek_khera http://www.khera.org/~vivek/
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: khera@kcilink.com
Subject: Re: adding column with not null constraint
In-Reply-To: <x7u1jjmrqm.fsf@onceler.kciLink.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox