Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id E67994762A6 for ; Fri, 18 Oct 2002 17:57:50 -0400 (EDT) Received: from mail-relay.trade-india.com (mail-relay.trade-india.com [203.196.129.235]) by postgresql.org (Postfix) with SMTP id 9936947628E for ; Fri, 18 Oct 2002 17:57:47 -0400 (EDT) Received: (qmail 5158 invoked from network); 18 Oct 2002 21:45:24 -0000 Received: from news1.trade-india.com (HELO www.trade-india.com) (130.94.20.27) by infocom-236-129-del.trade-india.com with SMTP; 18 Oct 2002 21:45:24 -0000 Received: (qmail 11565 invoked by uid 99); 18 Oct 2002 21:57:41 -0000 Received: from 203.145.130.142 (SquirrelMail authenticated user mallah) by mail.trade-india.com with HTTP; Sat, 19 Oct 2002 03:27:41 +0530 (IST) Message-ID: <1253.203.145.130.142.1034978261.squirrel@mail.trade-india.com> Date: Sat, 19 Oct 2002 03:27:41 +0530 (IST) Subject: Re: adding column with not null constraint From: To: In-Reply-To: References: X-Priority: 3 Importance: Normal X-MSMail-Priority: Normal Cc: X-Mailer: SquirrelMail (version 1.2.6) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200210/249 X-Sequence-Number: 9966 Hi Vivek, In 7.3 there will be a fully implemented ALTER TABLE command for making columns null or not null. Currently you can update 'attnotnull' of pg_attribute system catalog for the attrelid and attname. use pg_class system catalog for getting attrelid of a given relation. Regds MAllah. > 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/ > > ---------------------------(end of broadcast)--------------------------- TIP 5: Have you > checked our extensive FAQ? > > http://www.postgresql.org/users-lounge/docs/faq.html ----------------------------------------- Get your free web based email at trade-india.com. "India's Leading B2B eMarketplace.!" http://www.trade-india.com/