Re: One or Both Foregin Keys - Mailing list pgsql-general

From Tom Lane
Subject Re: One or Both Foregin Keys
Date
Msg-id 8831.1083374025@sss.pgh.pa.us
Whole thread Raw
In response to One or Both Foregin Keys  (Dennis Gearon <gearond@fireserve.net>)
Responses 1 foreign key to 2 different tables?
List pgsql-general
Dennis Gearon <gearond@fireserve.net> writes:
> I am working on a design where a location for something can have:
>     Fully qualified address with even building names, room numbers, and
> booth numbers.
> **-OR-**
>     GPS location
> **-OR-**
>     Both

> Other than triggers, is there a way to enforce this using tables and
> primary keys?

Put foreign key constraints on the address and GPS loc (so that they
must be either valid or NULL) and then add a CHECK constraint saying
they can't both be NULL.

            regards, tom lane

pgsql-general by date:

Previous
From: Sean Shanny
Date:
Subject: Re: "out of memory" error
Next
From: "FL"
Date:
Subject: unsubscribe