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

Re: Setting primary key on existing table

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Doug Silver <dsilver(at)urchin(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Setting primary key on existing table
Date: 2002-09-25 17:21:20
Message-ID: 11584.1032974480@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
Doug Silver <dsilver(at)urchin(dot)com> writes:
> I would like to be able to redefine a field in a table to be a foreign 
> reference -- however this field was initially defined as just "serial" and 
> not "serial primary key".  I tried to add that constraint to the table, but 
> it didn't work.

AFAIR, "serial" implies "unique not null" (at least in pre-7.3
releases), so your column is a primary key in all but name.  All you'd
get from marking it as primary key is not having to mention the column
name when defining the foreign key reference.  Is it good enough to
just write
		... foo int REFERENCES mytable(mycol)
?

			regards, tom lane

In response to

Responses

pgsql-novice by date

Next:From: Doug SilverDate: 2002-09-25 17:38:24
Subject: Re: Setting primary key on existing table
Previous:From: Doug SilverDate: 2002-09-25 16:52:55
Subject: Setting primary key on existing table

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