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

RE: Multiple primary keys

From: Mike Cianflone <mcianflone(at)littlefeet-inc(dot)com>
To: "'pgsql-docs(at)postgresql(dot)org'" <pgsql-docs(at)postgresql(dot)org>
Subject: RE: Multiple primary keys
Date: 2001-05-01 22:14:31
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-docs
	I figured it out. For future reference, you can't specify two
separate line in the create table construct, such as 

    mycol1 int4 PRIMARY KEY,
    mycol2 int4 PRIMARY KEY,

That will fail.

What you need to do is make a constraint in the same construct, such as
    CONSTRAINT primary_key_constraint PRIMARY KEY (mycol1, mycol2),

That will give you the tuple for the primary key set as mentioned below and
constrain the primary based upon two values rather than just one.


-----Original Message-----
From: Mike Cianflone 
Sent: Tuesday, May 01, 2001 2:39 PM
To: pgsql-docs(at)postgresql(dot)org
Subject: Multiple primary keys

	Does Postgres support multiple primary keys in any way? It doesn't
seem to directly support it in that if I try to specify two primary keys it
fails on the second one.
	What I'm trying to do is constrain the input based upon two columns,
rather than just one column. For example, the user can input (0,0), and then
(0,1), and then (0,2), and that would be fine. Then later the user could
input (1,0), and then (1,1) and then (1,2), and that would be fine also.
Since my constraint (or set of primary keys) would be based upon the two
columns, not just the first, it's ok to duplicate the first value as long as
both the first and second value are unique as a pair. 

	Does anyone know how to make a pair constraint?

Thanks for any pointers.

Mike Cianflone

pgsql-docs by date

Next:From: Christopher Kings-LynneDate: 2001-05-02 04:08:39
Subject: RE: Multiple primary keys
Previous:From: Mike CianfloneDate: 2001-05-01 21:39:10
Subject: Multiple primary keys

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