473,465 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Primary key inheritance problem

Hello,

I've a strange problem with inheritance on PostgreSQL 7.4.1. It seems
like tables don't inherits the primary key of the 'mother' table.
Here's a little sample to show my problem :

CREATE TABLE foo_a
(
pk_idmyfoo INT2 PRIMARY KEY NOT NULL,
myfoo_name VARCHAR(10)
);

CREATE TABLE child_foo
(
child_foo_nickname VARCHAR(20)
) INHERITS (foo_a);

CREATE TABLE childfoo_bookmarks
(
fk_idchildfoo INT2 NOT NULL REFERENCES child_foo (pk_idmyfoo),
url VARCHAR(250)
);

The error I get is :
ERROR: there is no unique constraint matching given keys for referenced
table "child_foo"

What can I do to solve that problem ?

Thanks in advance for your help !

--
Bruno Baguette - pg******@baguette.net

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #1
4 2819

On Fri, 27 Aug 2004, Bruno Baguette wrote:
Hello,

I've a strange problem with inheritance on PostgreSQL 7.4.1. It seems
like tables don't inherits the primary key of the 'mother' table.
Here's a little sample to show my problem :

CREATE TABLE foo_a
(
pk_idmyfoo INT2 PRIMARY KEY NOT NULL,
myfoo_name VARCHAR(10)
);

CREATE TABLE child_foo
(
child_foo_nickname VARCHAR(20)
) INHERITS (foo_a);

CREATE TABLE childfoo_bookmarks
(
fk_idchildfoo INT2 NOT NULL REFERENCES child_foo (pk_idmyfoo),
url VARCHAR(250)
);

The error I get is :
ERROR: there is no unique constraint matching given keys for referenced
table "child_foo"

What can I do to solve that problem ?


Well, to shut up the message you can add a constraint to child_foo's
version of pk_idmyfoo. However, as a note, that'll not guarantee
uniqueness between foo_a's pk_idmyfoo values and child_foo's ones.
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
On Fri, 2004-08-27 at 11:58, Bruno Baguette wrote:
Hello,

I've a strange problem with inheritance on PostgreSQL 7.4.1. It seems
like tables don't inherits the primary key of the 'mother' table. .... The error I get is :
ERROR: there is no unique constraint matching given keys for referenced
table "child_foo"
Primary and foreign key constraints are not inherited. This is a defect
in the current system.
What can I do to solve that problem ?


Create an index table to provide a unique key for the whole hierarchy.
Each member of the hierarchy has a foreign key reference to it na has
its own primary key on the referencing field. Use triggers to update
the index table.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Preach the word; be instant in season, out of season;
reprove, rebuke, exhort with all longsuffering and
doctrine." II Timothy 4:2
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #3
On Sunday 29 August at 12:34pm, Oliver Elphick had this to say:
Primary and foreign key constraints are not inherited. This is a defect
in the current system.


It almost seems like a FEATURE to me, since it creates a different and
easy way to create one-to-many relationships. But I didn't use it,
since the documentation says this is a Bad Thing that may be fixed
some day. If the child table inherits the primary key constraint from
the parent, why not just put it in the same table?

--

Matthew M Davis
<mm*@teledavis.com>

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #4
On Sun, 2004-08-29 at 18:07, Matthew M Davis wrote:
On Sunday 29 August at 12:34pm, Oliver Elphick had this to say:
Primary and foreign key constraints are not inherited. This is a defect
in the current system.


It almost seems like a FEATURE to me, since it creates a different and
easy way to create one-to-many relationships. But I didn't use it,
since the documentation says this is a Bad Thing that may be fixed
some day. If the child table inherits the primary key constraint from
the parent, why not just put it in the same table?


If you understand inheritance from the point of view of object-oriented
programming, you want to be able to have a hierarchy where the top level
has characteristics which are extended further down.

So all mammals are animals and all dogs are mammals, and all three
groups share common characteristics which are properties of the parent
class. But mammals have characteristics which are not applicable to all
animals and so are not appropriate to the parent class; similarly, dogs
have properties which are not common to all mammals.

Now one particular animal is either a mammal or it is not, and if it is,
it is either a dog or it is not. What it is governs which class it
belongs to in the hierarchy. Nevertheless, I may want to know about the
characteristics of animals without enquiring into the particular
characteristics of mammals; in that case an enquiry on the top-level of
the hierarchy is appropriate and will gather all information about all
animals. If I want to make a further enquiry about properties peculiar
to mammals, it is appropriate to start my enquiry at that level in the
hierarchy. However a particular animal can only be in one particular
class, therefore it would be preferable for the primary key to extend
over the whole hierarchy.

--
Oliver Elphick ol**@lfix.co.uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Preach the word; be instant in season, out of season;
reprove, rebuke, exhort with all longsuffering and
doctrine." II Timothy 4:2
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 23 '05 #5

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

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
3
by: Morten Aune Lyrstad | last post by:
Hi again! I'm having problems with inheritance. I have a base interface class called IObject. Next I have two other interfaces classes, IControl and ICommandMaster, which derives from IObject. ...
5
by: ma740988 | last post by:
Prefer composition to inheritance (can't recall which text I stole that line from) is one of the fundamental tenets thats engrained in my mind. Having said that inheritance requires careful...
14
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
22
by: Matthew Louden | last post by:
I want to know why C# doesnt support multiple inheritance? But why we can inherit multiple interfaces instead? I know this is the rule, but I dont understand why. Can anyone give me some concrete...
6
by: VR | last post by:
Hi, I read about Master Pages in ASP.Net 2.0 and after implementing some WinForms Visual Inheritance I tryed it with WebForms (let's say .aspx pages, my MasterPage does not have a form tag itself...
0
by: Bruno Baguette | last post by:
Hello, I've a strange problem with inheritance on PostgreSQL 7.4.1. It seems like tables don't inherits the primary key of the 'mother' table. Here's a little sample to show my problem : ...
5
by: colint | last post by:
Hi I'm fairly new to c++ and I have a question regarding inheritance. I'm trying to create a class based on 2 inherited classes, e.g. class A { ... } class B: public A
5
by: a | last post by:
Hi, I have an oop inheritance graph problem. What is the difference betweent the following 2 inheritance graph? How does the C++ solve the naming conflict problem for multiple inheritance...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.