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

Re: CREATE TABLE AS ...

From: Artur Pietruk <arturp(at)plukwa(dot)pdi(dot)net>
To: Raphael Bauduin <raphael(at)be(dot)easynet(dot)net>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: CREATE TABLE AS ...
Date: 2002-07-23 14:40:32
Message-ID: 20020723144032.GB4493@yoda.plukwa.net (view raw or flat)
Thread:
Lists: pgsql-admin
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(at)plukwa(dot)net

In response to

Responses

pgsql-admin by date

Next:From: Bruno Wolff IIIDate: 2002-07-23 15:44:36
Subject: Re: CREATE TABLE AS ...
Previous:From: Raphael BauduinDate: 2002-07-23 13:48:07
Subject: CREATE TABLE AS ...

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