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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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