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

From: Aleksey Dashevsky <postgres(at)luckynet(dot)co(dot)il>
To: Fran Fabrizio <fran(at)primary(dot)net>
Cc: pgsql-general(at)hub(dot)org
Subject: Re: [GENERAL] designating a column as primary key after creation
Date: 1998-08-13 07:53:55
Message-ID: Pine.LNX.3.96.SK.980813102731.5655B-100000@kesha.luckynet.co.il
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Maarten Boekhold 1998-08-13 09:28:21 lower(varchar)
Previous Message alfio su allnet 1998-08-13 07:48:27 Client for DOS environment