Re: alter table ad primary key

From: Alvaro Herrera <alvherre(at)atentus(dot)com>
To: Dmitry Tkach <dmitry(at)openratings(dot)com>
Cc: christoph(dot)dalitz(at)hs-niederrhein(dot)de, pgsql-general(at)postgresql(dot)org
Subject: Re: alter table ad primary key
Date: 2002-08-23 17:38:42
Message-ID: 20020823133842.542990ba.alvherre@atentus.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

En Fri, 23 Aug 2002 13:20:05 -0400
Dmitry Tkach <dmitry(at)openratings(dot)com> escribió:

>
> Christoph Dalitz wrote:
> > Hello,
> >
> > trying "alter table buecher add primary key (isbn);"
> > gives the error "ALTER TABLE / ADD CONSTRAINT is not implemented"
> > with PG 7.1.
> >
> > Does anybody know whether this works with a newer PG version?

Yes, it's supported since 7.2 I think.

> You don't really need all this...
>
> just:
>
> create unique index buecher_isbn_pkey on buecher(isbn);
> update pg_attribute set attnotnull='t' from pg_class where attrelid=oid and relname='buecher' and attname='isbn';
>
> This will have exactly the same effect as making it a primary key. The *only* difference is that \d will not say it's a primary
> key... Functionally, it is completely the same thing though...

Another side effect of this method is that when creating foreign key
references you will have to declare the column explicitly.

I think to get it completely you also have to set the indisprimary bit
on the pg_index tuple of the index... Not that I'm suggesting messing
with system catalog though: it's unportable and a little mistake can
render your database useless. Better to upgrade....

--
Alvaro Herrera (<alvherre[a]atentus.com>)
"Pensar que el espectro que vemos es ilusorio no lo despoja de espanto,
sólo le suma el nuevo terror de la locura" (Perelandra, CSLewis)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dmitry Tkach 2002-08-23 17:40:40 Re: alter table ad primary key
Previous Message Dmitry Tkach 2002-08-23 17:20:05 Re: alter table ad primary key