Re: foreign key question

From: Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: foreign key question
Date: 2011-01-05 10:40:08
Message-ID: 201101051040.08575.gary.stainburn@ringways.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wednesday 05 January 2011 09:53:43 Gary Stainburn wrote:
> Now I want to set up a new access level table specific to the itinerary,
> along the lines of
>
> u_id int4 not null references users(u_id)
> fl_level int4 not null references facility_levels(16, fl_level)
>
> Firstly, is this possible, and secondly how would I do it?

I've managed a work-around by creating a column that defaults to 16 and then
used ALTER TABLE ADD CONSTRAINT to add a foreign key with two pairs of keys.

This feels wrong though as my table now has a column that is ultimately
redundant, and worse can be changed to a wrong value.

Ok, I've sorted the last bit by adding a check constraint to make sure it
always contains 16, but it still feels wrong.

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tarsis Lima 2011-01-05 14:18:26 return records with more than one occurrences
Previous Message Gary Stainburn 2011-01-05 09:53:43 foreign key question