foreign keys - Mailing list pgsql-hackers

From Sam Mason
Subject foreign keys
Date
Msg-id 20071212132031.GC1676@frubble.xen.chris-lamb.co.uk
Whole thread Raw
List pgsql-hackers
Hi,

How hard/generally useful would it be to allow the target of a foreign
key to be on a set of columns where only a subset of them actually have
a unique constraint.  For example:
 CREATE TABLE base (   id   INTEGER NOT NULL PRIMARY KEY,   type INTEGER NOT NULL );
 CREATE TABLE type1info (   id   INTEGER NOT NULL PRIMARY KEY,   type INTEGER NOT NULL CHECK (type = 1),     FOREIGN
KEY(id,type) REFERENCES base (id,type) );
 

It's possible to create a UNIQUE constraint on base(id,type) but it
seems redundant as the PRIMARY KEY constraint on id already ensures
uniqueness.

Somewhat independently, it would be nice to allow constant expressions
to be used on the left-hand-side of foreign key constraints.  Allowing
them on the RHS seems nice for completeness, but appears completely
useless in practical terms.  The second table would simply become:
 CREATE TABLE type1info (   id INTEGER NOT NULL PRIMARY KEY,     FOREIGN KEY (id,1) REFERENCES base (id,type) );

 Sam


pgsql-hackers by date:

Previous
From: "Zeugswetter Andreas ADI SD"
Date:
Subject: Re: WORM and Read Only Tables (v0.1)
Next
From: Gregory Stark
Date:
Subject: ScalarArrayOp advancing array keys