Advice on merging two primary keys...

Поиск
Список
Период
Сортировка
От Eric D. Nielsen
Тема Advice on merging two primary keys...
Дата
Msg-id 46693114-7CFD-43E1-8FF5-6A406B83E19E@mit.edu
обсуждение исходный текст
Ответы Re: Advice on merging two primary keys...  (Richard Huxton <dev@archonet.com>)
Список pgsql-general
I've come into a situation where I will often need to merge two
primary keys, with numerous foreign keys hanging off of them.  For
instance:

CREATE TABLE people (
   peopleid SERIAL PRIMARY KEY,
   firstname TEXT NOT NULL,
   lastname TEXT NOT NULL
);

CREATE TABLE users (
   username TEXT PRIMARY KEY,
   peopleid INT NOT NULL REFERENCES people ON UPDATE CASCADE ON
DELETE RESTRICT,
  ...
);

CREATE TABLE results (
   peopleid INT NO NULL REFERENCES peopleid ON UPDATE CASCADE ON
DELETE CASCADE,
   eventid INT ...
   score  INT...
);

There are some other tables keyed by peopleid that are normally only
populated by user related peopleids.

The site in question is a sports ranking site.  Typically speaking
most "people" are not "users" are have their information populated
from placement sheets.  Some people will later create an account and
after in real life authentication the records need to be merged -- ie
there will be records from both peopleid that will need should be
adjusted to a single value.

While any update of the either primary key will cascade to all
relevant tables, such an update is disallowed for uniqueness reasons.

Is there a good SQL-base method to accomplish this type of merging or
does this need application logic?

Eric

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

Предыдущее
От: Matt Miller
Дата:
Сообщение: Re: Building Latest (8.1)
Следующее
От: Andreas
Дата:
Сообщение: Re: automating backup ?