Tod McQuillin wrote:
> On Wed, 1 Nov 2000 limin@www.pumpkinnet.com wrote:
>
> > The db schema we have need to do a cycle references. I.e.,
> > an attribute in table_1 references the key in table_2 and
> > an attribute in table_2 references the key in table_1. However,
> > PostgreSQL does not allow us to make reference to an "non-existing" table!
> >
> > Is there any work-around on this issue?
>
> I had the same problem. You can play around with creating the tables
> without the RI checks and adding the constraints later, but I found this
> clumsy.
>
> The solution I used was to have a third table with attributes referencing
> keys from table_1 and table_2. This avoids the problem of inserting
> references to keys which don't exist yet, and you can use joins from
> table_[12] to table_3 to do the same queries you would have done with the
> cross-referential tables.
One of the reasons to setup referential integrity constraints
is to avoid inserting references to keys that don't exist, so
getting around it with your 3-table setup looks a little odd
to me.
You'd better think about declaring your constraints INITIALLY
DEFERRED and cover the key- and reference-insertions by
proper transaction blocks.
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck@Yahoo.com #