473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Foreign keys on inherited attributes

Greetings,

I'm using pg 7.3.5 and playing with table inheritance, and I've run into the
fact that foreign keys cannot be defined on inherited attributes. (As much
is stated in the documentation, but it didn't sink in until I ran into the
fact.)

The documents say this will probably be fixed in a future release. My
question is, are there any definite plans in that direction at this point?

Take care,
Shawn Harrison
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 22 '05 #1
2 1309
On Mon, 26 Jan 2004, Shawn Harrison wrote:
I'm using pg 7.3.5 and playing with table inheritance, and I've run into the
fact that foreign keys cannot be defined on inherited attributes. (As much
is stated in the documentation, but it didn't sink in until I ran into the
fact.)

The documents say this will probably be fixed in a future release. My
question is, are there any definite plans in that direction at this point?


AFAIK, there's nobody actively looking at dealing with the various
constraint/inheritance issues at this point.
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #2
On Mon, 2004-01-26 at 19:23, Shawn Harrison wrote:
I'm using pg 7.3.5 and playing with table inheritance, and I've run into the
fact that foreign keys cannot be defined on inherited attributes. (As much
is stated in the documentation, but it didn't sink in until I ran into the
fact.)

I have a similar problem and have two inelegant workarounds.

1) Use triggers which does the key check. I don't know of any simple way
to cascade deletes or updates.

2) Use inheritance to define the FK-containing tables as well, one for
each PK-containing table. The supertable of these is provides the
abstraction you sought.

Example:

I wanted a hierarchy of models of different types (each with
table-specific data) and heterogeneous sets of models, roughly like
this:
(if the word model is distracting, think instead of jobs and sets of
related job families, or some such analogy)

model modelA modelB modelC (model{A,B,C} ISA model)
mid(PK) mid(PK) mid(PK) mid(PK)
colA1 colB1 colC1

setmodel
mid(FK)
sid(FK)

set
sid(PK)
name
As you noted, making modelsetmodel.mid a FK of model.mid doesn't work
because the PK index is NOT inherited.
Instead, I have this:

model modelA modelB modelC (model{A,B,C} ISA model)
mid(PK) mid(PK) mid(PK) mid(PK)
colA1 colB1 colC1

setmodel setmodelA setmodelB setmodelC (setmodel{A,B,C} ISA setmodel)
mid(FK) mid(FK) mid(FK) mid(FK)
sid(FK) sid(FK) sid(FK) sid(FK)

set
sid(PK)
name
Of course, setmodelA.mid is now a FK of modelA.mid, and so on for B and
C. I can still select from setmodel to get the heterogeneous sets I
originally sought.

I hope that helps,
Reece
--
Reece Hart, http://www.in-machina.com/~reece/, GPG:0x25EC91A0

Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bodza Bodza | last post by:
I'm having an argument with an incumbent self-taught programmer that it is OK to use null foreign keys in database design. My take is the whole point of a foreign key is that it's not supposed...
31
by: Robert Brown | last post by:
Let's say I have a type hierarchy: (just an example) the general entity customer: CREATE TABLE customer(customer_id int, customer_name varchar(250), customer_type int) three specific...
0
by: Christopher Boomer | last post by:
I am relatively new to the world of XML and python, and I think I am still missing some of the basic concepts. It cannot be as hard as I think, or programmers would be flocking to it the way they...
0
by: Scott Ribe | last post by:
I've got a problem which I think may be a bug in Postgres, but I wonder if I'm missing something. Two tables, A & B have foreign key relations to each other. A 3rd table C, inherits from A. A...
1
by: Greg Hulands | last post by:
I have a table called Person that has a primary key personID. Another table called ProUser that inherits from Person. In another table called ProPriceSchedule I have a foreign key constraint to the...
6
by: Brendan Jurd | last post by:
Hi all, I read on the manual page for Inheritance that: "A limitation of the inheritance feature is that indexes (including unique constraints) and foreign key constraints only apply to single...
0
by: peter | last post by:
I have a Database ( MS Access 2000 ) in which there's 3 Tables(E1_Customer, E2_Supplier and E3_Product). Two Attributes in E1_Customer are the foreign keys of Table E2_Supplier_ID and...
0
by: Eva Hovelsrød | last post by:
Hi, I just realized that foreign keys to an inherited table don't work when the record was inserted into a child table. That is postgresql-7.3.2-3. Does anyone know whether anyone is working on...
5
by: Bob Stearns | last post by:
For good and sufficient reasons I wish to insure that a primary key of table 1 is not a primary key of table 2. The following does not work: ALTER TABLE IS3.AUCTION_SUPER_CATEGORIES ADD...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.