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



-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Reply via email to