[GENERAL] Foreign key references a unique index instead of a primary key

Поиск
Список
Период
Сортировка
От Ivan Voras
Тема [GENERAL] Foreign key references a unique index instead of a primary key
Дата
Msg-id CAF-QHFUm+yMRr9m0unRD6CfHqK12Pfhao_hdXjuLG-t+icbBnQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: [GENERAL] Foreign key references a unique index instead of aprimary key
Re: [GENERAL] Foreign key references a unique index instead of aprimary key
Список pgsql-general
Hello,

I've inherited a situation where:
  • a table has both a primary key and a unique index on the same field. 
  • at some time, a foreign key was added which references this table (actually, I'm not sure about the sequence of events), which has ended up referencing the unique index instead of the primary key.
Now, when I've tried dropping the unique index, I get an error that the foreign key references this index (with a hint I use DROP...CASCADE).

This drop index is a part of an automated plpgsql script which deletes duplicate indexes, so I'm interested in two things:
  1. How to detect if a foreign key depends on an index I'm about to drop, so I can skip it
  2. Is there a way to get around this situation, maybe modify the pg_constraint table or other tables to reference the index / primary key I want
?

This is on PostgreSQL 9.3.

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

Предыдущее
От: Moreno Andreo
Дата:
Сообщение: Re: [GENERAL] Latest PostgreSQL on Raspbian Jessie
Следующее
От: Leknín Řepánek
Дата:
Сообщение: Re: [GENERAL] Move rows from one database to other