pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Richards <michael@fastmail.ca>
To: pgsql-sql@postgresql.org
Subject: 7.1 REFERENCES contstraints
Date: Sun,  6 May 2001 17:55:17 -0400 (EDT)
Message-ID: <3AF5C845.00008D.78696@frodo.searchcanada.ca> (raw)

I see that the REFERENCES constraint is a little more restrictive in 
7.1. I need to have a table with a constraint so one of it's columns 
must exist in a second table. This is not a key, since there may be N 
columns in the second table that match. Any ideas on how I should 
create this?

CREATE table foo(
id serial,
permissions int4,
FOREIGN KEY (permissions) REFERENCES bar(permid));

used to work in 7.0 but now it complains with:
psql:ddl.sql:103: ERROR:  UNIQUE constraint matching given keys for 
referenced table "permissions" not found

-Michael
_________________________________________________________________
     http://fastmail.ca/ - Fast Free Web Email for Canadians
From pgsql-sql-owner@postgresql.org  Sun May  6 21:34:09 2001
Received: from megazone23.bigpanda.com ([216.136.151.41])
	by postgresql.org (8.11.3/8.11.1) with ESMTP id f471Y5A08805
	for <pgsql-sql@postgresql.org>; Sun, 6 May 2001 21:34:05 -0400 (EDT)
	(envelope-from sszabo@megazone23.bigpanda.com)
Received: from localhost (sszabo@localhost)
	by megazone23.bigpanda.com (8.11.2/8.11.2) with ESMTP id f471XvJ74266;
	Sun, 6 May 2001 18:33:57 -0700 (PDT)
Date: Sun, 6 May 2001 18:33:57 -0700 (PDT)
From: Stephan Szabo <sszabo@megazone23.bigpanda.com>
To: Michael Richards <michael@fastmail.ca>
cc: pgsql-sql@postgresql.org
Subject: Re: 7.1 REFERENCES contstraints
In-Reply-To: <3AF5C845.00008D.78696@frodo.searchcanada.ca>
Message-ID: <Pine.BSF.4.21.0105061830030.74241-100000@megazone23.bigpanda.com>
MIME-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
X-Archive-Number: 200105/42
X-Sequence-Number: 2843

On Sun, 6 May 2001, Michael Richards wrote:

> I see that the REFERENCES constraint is a little more restrictive in 
> 7.1. I need to have a table with a constraint so one of it's columns 
> must exist in a second table. This is not a key, since there may be N 
> columns in the second table that match. Any ideas on how I should 
> create this?
> 
> CREATE table foo(
> id serial,
> permissions int4,
> FOREIGN KEY (permissions) REFERENCES bar(permid));
> 
> used to work in 7.0 but now it complains with:
> psql:ddl.sql:103: ERROR:  UNIQUE constraint matching given keys for 
> referenced table "permissions" not found

You can't do this using references.  SQL requires that the second table
must have a unique constraint on those columns.  The semantics of
match partial would be close (but we don't have that yet), but the
match unspecified and match full semantics don't really work right
if it isn't unique (for example, any deletes from the second table
where referenced would fail even if there were additional rows
that could satisfy the constraint, also, cascaded deletes would
for example happen on the first deletion of a matching row).  While
you could make the constraint in 7.0, it really didn't work "right."





Message-ID: <3AF5C845.00008D.78696@frodo.searchcanada.ca>
Permalink:  ../3AF5C845.00008D.78696@frodo.searchcanada.ca/
Also on:    postgresql.org/message-id/3AF5C845.00008D.78696@frodo.searchcanada.ca

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: michael@fastmail.ca
  Subject: Re: 7.1 REFERENCES contstraints
  In-Reply-To: <3AF5C845.00008D.78696@frodo.searchcanada.ca>
  References: <3AF5C845.00008D.78696@frodo.searchcanada.ca>

* 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