pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Denis Bucher <dbucher@niftycom.com>
To: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Are circular REFERENCES possible ?
Date: Tue, 07 Aug 2001 11:54:52 +0200
Message-ID: <5.1.0.14.0.20010807114609.00a18490@mail.niftycom.com> (raw)


Hello !

I have a case where I wanted to do circular REFERENCES, is this
impossible ?

Just an example where it would be useful :

We deliver to the *shops* of our *customers*.
We have therefore two tables :
  - customers (enterprise, financial information, and so on...)
  - shop (with a name, street, phone number, name of manager)

Now, each shop REFERENCES a customer so that we know
to which customer belongs a shop.

AND, each customer has a DEFAULT shop for deliveries, i.e. most
customers only have one shop, or a main shop and many small ones.
Therefore a customer should REFERENCES the 'main' or 'default' shop.

Which leads to :

CREATE TABLE shops ( id_shop SERIAL PRIMARY KEY, id_cust integer REFERENCES 
customers, .......)
CREATE TABLE customers ( id_cust SERIAL PRIMARY KEY, id_defaultshop integer 
REFERENCES shops, .......)

But this doesn't work ! Postgres complains like "ERROR:  Relation 
'customers' does not exist"
when creating 'shops'.

Someone told me I should create a third table, ok, but in this case I loose 
the total
control about my logic... Do you have a suggestion ?

Thanks a lot in advance !

Denis




view thread (15+ messages)  latest in thread

Message-ID: <5.1.0.14.0.20010807114609.00a18490@mail.niftycom.com>
Permalink:  ../5.1.0.14.0.20010807114609.00a18490@mail.niftycom.com/
Also on:    postgresql.org/message-id/5.1.0.14.0.20010807114609.00a18490@mail.niftycom.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dbucher@niftycom.com
  Subject: Re: Are circular REFERENCES possible ?
  In-Reply-To: <5.1.0.14.0.20010807114609.00a18490@mail.niftycom.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox