Re: alter table ad primary key

Поиск
Список
Период
Сортировка
От Dmitry Tkach
Тема Re: alter table ad primary key
Дата
Msg-id 3D666EC5.602@openratings.com
обсуждение исходный текст
Ответ на alter table ad primary key  (Christoph Dalitz <christoph.dalitz@hs-niederrhein.de>)
Ответы Re: alter table ad primary key  (Alvaro Herrera <alvherre@atentus.com>)
Список pgsql-general
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?
>
> Did someone already implement a workaround in form of a stored
> procedure that does the following:
>   - copy the table entirely to a temporary table
>   - remember all indices, constraints, rules and triggers on the old table
>     (is that possible at all?)
>   - drop the old table
>   - recreate the table with a primary key
>   - copy the temp table bakc
>   - drop the temp table
> ?
>


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...

I hope, it helps...

Dima


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

Предыдущее
От: Dmitry Tkach
Дата:
Сообщение: 'on delete' rule: bug or feature...
Следующее
От: Alvaro Herrera
Дата:
Сообщение: Re: alter table ad primary key