Re: DEFERRABLE NOT NULL constraint - Mailing list pgsql-general

From Jasen Betts
Subject Re: DEFERRABLE NOT NULL constraint
Date
Msg-id kf01qa$dvn$1@gonzo.reversiblemaps.ath.cx
Whole thread Raw
In response to Re: DEFERRABLE NOT NULL constraint  (Andreas Joseph Krogh <andreak@officenet.no>)
List 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 by date:

Previous
From: Scott Marlowe
Date:
Subject: Re: REINDEX deadlock - Postgresql -9.1
Next
From: Jasen Betts
Date:
Subject: Re: DEFERRABLE NOT NULL constraint