pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <rbt@rbt.ca>
To: Saad Saeed <saads@umich.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Creating a foreign key on the Union of two tables
Date: 07 Apr 2003 12:48:56 -0400
Message-ID: <1049734135.40144.17.camel@jester> (raw)
In-Reply-To: <a811aba0.0304061353.664e2263@posting.google.com>
References: <a811aba0.0304061353.664e2263@posting.google.com>

On Sun, 2003-04-06 at 17:53, Saad Saeed wrote:
> I have 2 tables "A" and "B" in mySQL. They both have an attribute 'id'
> which is unique between the 2 tables. I want the union of these 2
> attributes to be a foreign key in a 3rd table "C". How do I specify
> this constraing in sql (mySQL) in table C? And for complex reasons I
> cannot merge the 2 tables A and B.

Can't say for MySQL (since this is a PostgreSQL list!!!!!), but creating
a foreign key like that to 2 different tables is against spec because
one cannot create a unique constraint across 2 tables.

That said, you could create a set of pl/pgsql functions that can imitate
what a foreign key does and will work in the situation you describe --
if you're using PostgreSQL.

-- 
Rod Taylor <rbt@rbt.ca>

PGP Key: http://www.rbt.ca/rbtpub.asc

Attachments:

  signature.asc (application/pgp-signature, 186B) download

view thread (5+ messages)  latest in thread

Message-ID: <1049734135.40144.17.camel@jester>
Permalink:  ../1049734135.40144.17.camel@jester/
Also on:    postgresql.org/message-id/1049734135.40144.17.camel@jester

 · 

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: rbt@rbt.ca, saads@umich.edu
  Subject: Re: Creating a foreign key on the Union of two tables
  In-Reply-To: <1049734135.40144.17.camel@jester>

* 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