unique keys / foreign keys on two tables - Mailing list pgsql-sql

From Gary Stainburn
Subject unique keys / foreign keys on two tables
Date
Msg-id 201211291014.27989.gary.stainburn@ringways.co.uk
Whole thread Raw
Responses Re: unique keys / foreign keys on two tables
List pgsql-sql
I'm designing the schema to store a config from our switchboards.

As with all PBX's the key is the dialed number which is either an extension 
number or a group (hunt/ring/pickup) number.

I have two tables, one for extensions and one for groups, basically

ext_id    int4 primary key
ext_desc    text
....
....
....

and



grp_id    int4 primary key
grp_desc    text
.....
.....
.....

I now need to be able to ensure the id field is unique across both tables. 
Presumably I can do this with a function and a constraint for each table. 
Does anyone have examples of this?


Next I have other tables that refer to *destinations* which will be an ID that 
could be either an extension or a group. Examples are 'Direct Dial In' 
numbers which could point to either.  How would I do that?

-- 
Gary Stainburn
Group I.T. Manager
Ringways Garages
http://www.ringways.co.uk 



pgsql-sql by date:

Previous
From: Guillaume Lelarge
Date:
Subject: Re: \copy multiline
Next
From: Wolfe Whalen
Date:
Subject: Re: unique keys / foreign keys on two tables