Having an optional foreign key (ie. sometimes NULL) ? - Mailing list pgsql-general

From Tom
Subject Having an optional foreign key (ie. sometimes NULL) ?
Date
Msg-id 1047596316.3e710d1c84742@IMP-3.2
Whole thread Raw
Responses Re: Having an optional foreign key (ie. sometimes NULL) ?  (Manfred Koizar <mkoi-pg@aon.at>)
Re: Having an optional foreign key (ie. sometimes NULL) ?  (Ryan Mahoney <ryan@paymentalliance.net>)
List pgsql-general
Hello,

  I have the following tables:

    - company (eg. ABC Shipping Inc.)
    - product (eg. table, chair, pen, pencil)
    - client (eg. Joe's Insurance Company)

and they relate to each other as follows:

    - a company has clients (company is a foreign key in client)
    - a company sells products (company is a foreign key in client)

which is all well and good until I come to one specification in my design
document which says that "some products will only be available to a single
client whereas other products will be available to all clients".

  I thought the best way to get around this would be to have the client as a
foreign key in products but for products available to all clients this won't
work.

  Can someone advise how I can overcome this?

  Thanks, Tom.

pgsql-general by date:

Previous
From: "scott.marlowe"
Date:
Subject: Re: PL/Java (was: stored procedures)
Next
From: Tom Lane
Date:
Subject: Re: functional indexes and their costs