Re: Setting primary key on existing table

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Setting primary key on existing table
Дата
Msg-id 11584.1032974480@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Setting primary key on existing table  (Doug Silver <dsilver@urchin.com>)
Ответы Re: Setting primary key on existing table  (Doug Silver <dsilver@urchin.com>)
Список pgsql-novice
Doug Silver <dsilver@urchin.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

В списке pgsql-novice по дате отправления:

Предыдущее
От: Doug Silver
Дата:
Сообщение: Setting primary key on existing table
Следующее
От: Doug Silver
Дата:
Сообщение: Re: Setting primary key on existing table