Re: Are circular REFERENCES possible ?

From: "William Courtier" <wcourtier(at)travelprice(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Are circular REFERENCES possible ?
Date: 2001-08-07 10:09:59
Message-ID: 9koepm$420$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I denis,

I don't know if you can use a circular REFERENCES, but why you try made a
references before the table is created (customers). You should create the
references after and use the foreign key if circular references does not
work.

William
"Denis Bucher" <dbucher(at)niftycom(dot)com> a crit dans le message news:
5(dot)1(dot)0(dot)14(dot)0(dot)20010807114609(dot)00a18490(at)mail(dot)niftycom(dot)com(dot)(dot)(dot)
>
> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Grigoriy G. Vovk 2001-08-07 10:16:47 Re: Are circular REFERENCES possible ?
Previous Message Denis Bucher 2001-08-07 09:54:52 Are circular REFERENCES possible ?