Search Postgresql Archives

Re: DEFERRABLE NOT NULL constraint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux