pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Raphael Bauduin <raphael.bauduin@be.easynet.net>
To: Artur Pietruk <arturp@plukwa.pdi.net>
Cc: Raphael Bauduin <raphael@be.easynet.net>
Cc: pgsql-admin@postgresql.org
Subject: Re: CREATE TABLE AS ...
Date: Wed, 24 Jul 2002 10:14:17 +0200
Message-ID: <20020724081417.GA7419@raphael> (raw)
In-Reply-To: <20020723144032.GB4493@yoda.plukwa.net>
References: <20020723134807.GB22069@raphael>
	<20020723144032.GB4493@yoda.plukwa.net>

Hi,

Thanks for the tips, but although the result is the same as a primary
key constraint, I'm not sure it will fit my needs as I want to use the
primary key in a foreign key constraint in another table. I made it with
a copy and it works fine.

Raph

On Tue, Jul 23, 2002 at 04:40:32PM +0200, Artur Pietruk wrote:
> 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



view thread (6+ messages)  latest in thread

Message-ID: <20020724081417.GA7419@raphael>
Permalink:  ../20020724081417.GA7419@raphael/
Also on:    postgresql.org/message-id/20020724081417.GA7419@raphael

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: raphael.bauduin@be.easynet.net, arturp@plukwa.pdi.net, raphael@be.easynet.net
  Subject: Re: CREATE TABLE AS ...
  In-Reply-To: <20020724081417.GA7419@raphael>
  References: <20020723134807.GB22069@raphael> <20020723144032.GB4493@yoda.plukwa.net> <20020724081417.GA7419@raphael>

* 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