Received: from yoda.plukwa.net (yoda.plukwa.net [213.146.36.61]) by postgresql.org (Postfix) with ESMTP id B852D4758F5 for ; Tue, 23 Jul 2002 10:40:59 -0400 (EDT) Received: from arturp by yoda.plukwa.net with local (Exim 3.35 #1 (Debian)) id 17X0q0-0000ft-00; Tue, 23 Jul 2002 16:40:32 +0200 Date: Tue, 23 Jul 2002 16:40:32 +0200 From: Artur Pietruk To: Raphael Bauduin Cc: pgsql-admin@postgresql.org Subject: Re: CREATE TABLE AS ... Message-ID: <20020723144032.GB4493@yoda.plukwa.net> References: <20020723134807.GB22069@raphael> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20020723134807.GB22069@raphael> User-Agent: Mutt/1.4i X-Archive-Number: 200207/315 X-Sequence-Number: 4999 On Tue, Jul 23, 2002 at 03:48:07PM +0200, Raphael Bauduin wrote: > Hi, Hello, > In a data model change, I wanted to use the "create table as select" > feature. However, I want that table to have a primary key defined, and > thus a field defined as NOT NULL. I didn't find a way to add a NOT NULL > constraint on a column of an existing table. If there isn't, what's the > best way to go? A COPY? Yes, it looks that you cannot add NOT NULL constraint. But check if this could work for you: == 8< === ALTER TABLE your_table ADD CONSTRAINT my_constr1 CHECK (your_column IS NOT NULL UNIQUE); ALTER TABLE your_table ADD CONSTRAINT my_constr2 UNIQUE (your_column); == 8< === It is not marked as "Primary Key", but it does the same job: checks that column is UNIQUE and NOT NULL. Best regards, -- --- Artur Pietruk, arturp@plukwa.net