Unix Technical Forum

foreign keys

This is a discussion on foreign keys within the pgsql Hackers forums, part of the PostgreSQL category; --> Hi, How hard/generally useful would it be to allow the target of a foreign key to be on a ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-15-2008, 10:37 PM
Sam Mason
 
Posts: n/a
Default foreign keys

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

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:53 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com