pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: pgsql-sql@postgresql.org
Subject: Re: foreign key question
Date: Wed, 5 Jan 2011 10:40:08 +0000
Message-ID: <201101051040.08575.gary.stainburn@ringways.co.uk> (raw)
In-Reply-To: <201101050953.43830.gary.stainburn@ringways.co.uk>
References: <201101050953.43830.gary.stainburn@ringways.co.uk>

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 



view thread (3+ messages)  latest in thread

Message-ID: <201101051040.08575.gary.stainburn@ringways.co.uk>
Permalink:  ../201101051040.08575.gary.stainburn@ringways.co.uk/
Also on:    postgresql.org/message-id/201101051040.08575.gary.stainburn@ringways.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: gary.stainburn@ringways.co.uk
  Subject: Re: foreign key question
  In-Reply-To: <201101051040.08575.gary.stainburn@ringways.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox