Re: PRIMARY KEY on a *group* of columns imply that each column is NOT

From: ptjm(at)interlog(dot)com (Patrick TJ McPhee)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: PRIMARY KEY on a *group* of columns imply that each column is NOT
Date: 2005-04-27 05:19:32
Message-ID: 3d8ln3F6qd8fkU1@uni-berlin.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <20050426203938(dot)GA18628(at)nic(dot)fr>,
Stephane Bortzmeyer <bortzmeyer(at)nic(dot)fr> wrote:

% But it does not apply to primary keys containing a group of
% columns. In that case (my case), columns do not have to be UNIQUE. But
% they have to be NOT NULL, which puzzles me.

It does apply to primary keys containing groups of columns.

You can get the table definition you want by using a unique constraint,
but you should know that in SQL, unique constraints don't apply to
rows containing null values in the constrained columns. If you
do this:

create table x (
name TEXT NOT NULL,
address INET,
CONSTRAINT na UNIQUE (name, address)
);

your table definition will be as you want it, but the constraint you
want won't be there.

$ INSERT INTO x VALUES ('alpha');
INSERT 194224 1
$ INSERT INTO x VALUES ('alpha');
INSERT 194225 1
$ INSERT INTO x VALUES ('alpha');
INSERT 194226 1
$ INSERT INTO x VALUES ('alpha');
INSERT 194227 1

--

Patrick TJ McPhee
North York Canada
ptjm(at)interlog(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Patrick.FICHE 2005-04-27 06:12:03 Re: Change Windows path to Unix path...
Previous Message Ron Mayer 2005-04-27 04:52:53 Re: Performance difference between ANY and IN, also array syntax