Re: [GENERAL] designating a column as primary key after creation - Mailing list pgsql-general

From Aleksey Dashevsky
Subject Re: [GENERAL] designating a column as primary key after creation
Date
Msg-id Pine.LNX.3.96.SK.980813102731.5655B-100000@kesha.luckynet.co.il
Whole thread Raw
In response to designating a column as primary key after creation  (Fran Fabrizio <fran@primary.net>)
Responses Nulls (was Re: designating a column as primary key after creation)
List 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 by date:

Previous
From: "alfio su allnet"
Date:
Subject: Client for DOS environment
Next
From: Maarten Boekhold
Date:
Subject: lower(varchar)