Re: [GENERAL] designating a column as primary key after creation

Поиск
Список
Период
Сортировка
От Aleksey Dashevsky
Тема Re: [GENERAL] designating a column as primary key after creation
Дата
Msg-id Pine.LNX.3.96.SK.980813102731.5655B-100000@kesha.luckynet.co.il
обсуждение исходный текст
Ответ на designating a column as primary key after creation  (Fran Fabrizio <fran@primary.net>)
Ответы Nulls (was Re: designating a column as primary key after creation)  (Herouth Maoz <herouth@oumail.openu.ac.il>)
Список pgsql-general

On Wed, 12 Aug 1998, Fran Fabrizio wrote:

>
> Why does postgres choke on the following:
>
> alter table mytable add constraint mycolumn_pk primary key(mycolumn);
>
> is this possible in a postgres database?  if not, what's an easy
> workaround, i really need to have this column as primary key.

Unfortunately the syntax you wanted to use is not allowed in PostgresSQL
as well as
1. alter table <tablename> drop column <colname>
and
2. alter table <tablename> modify column ....

Nevertheless, there is at least one workaround for your case: you can
create (at any time!) unique index on your table using any column or
column combination from already existing table. The only weakness of this
method is that NULL values are not forbidded in unique index , so you can
lost uniquness if there will be some rows with NULLs in key column(s).
(note, that each NULL is treated as new  value, I mean one NULL is
note equal to another one!)

for details refer to create_index(l) and drop_index(l) man pages.

Al.


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

Предыдущее
От: "alfio su allnet"
Дата:
Сообщение: Client for DOS environment
Следующее
От: Maarten Boekhold
Дата:
Сообщение: lower(varchar)