Re: DEFERRABLE NOT NULL constraint

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: DEFERRABLE NOT NULL constraint
Дата
Msg-id kf01qa$dvn$1@gonzo.reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Re: DEFERRABLE NOT NULL constraint  (Andreas Joseph Krogh <andreak@officenet.no>)
Список pgsql-general
here's a relatively clean way to do circular references:

 given the circular reference:

  table a (
    i serial primary key ,
    j integer references b(j) deferrable initially deferred
          );

  table b (
    j serial primary key ,
    i integer references a(i)
           );

to make inserts easier put the default value of the column  b.i
onto column a.j also (so both columns have the same sequence as their
default value)

then you ans do an INSERT INTO a [...] RETURNING i,j and have the
primary and foreign keys values needed for the new b row, without
needing to explictly reference the sequence in the query or
beforehand.

getting an ORM to follow that process may not be so easy, but is
probably the right thing to do.




--
⚂⚃ 100% natural

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

Предыдущее
От: Scott Marlowe
Дата:
Сообщение: Re: REINDEX deadlock - Postgresql -9.1
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: DEFERRABLE NOT NULL constraint