473,811 Members | 3,701 Online
Bytes | Software Development & Data Engineering Community
+ 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_nickn ame VARCHAR(20)
) INHERITS (foo_a);

CREATE TABLE childfoo_bookma rks
(
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******@baguet te.net

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

Nov 23 '05 #1
4 2871

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_nickn ame VARCHAR(20)
) INHERITS (foo_a);

CREATE TABLE childfoo_bookma rks
(
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*******@postg resql.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 YourEmailAddres sHere" to ma*******@postg resql.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
4383
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 files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
3
2473
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. My problem is that I have a /third/ class, CCommand, which derives from both IControl and ICommandmaster... The error message says (Weird.....)
5
1344
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 thought. To compound things, when dealing with inheritance 'virtuality' can only be experienced through base pointers to derived. There are ocassions though that I dont need a (particulay) 'virtual' function in base. In which case I'll have to...
14
12927
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 all obvious in VBA which lacks inheritance. I'm trying the explanation again now. I often find cases where a limited form of inheritance would eliminate duplication my code that seems impossible to eliminate otherwise. I'm getting very...
22
23391
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 examples?
6
2103
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 so, cannot be called a WebForm itself, the child pages will implement forms). I created a Master.aspx page and removed all HTML from it, added some code to the .aspx.vb file to add controls to my page. Then I created a Child.aspx and changed the...
0
361
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 : CREATE TABLE foo_a ( pk_idmyfoo INT2 PRIMARY KEY NOT NULL, myfoo_name VARCHAR(10)
5
2759
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
3516
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 problem? Thanks A / \
0
10393
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10405
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9208
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7671
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6893
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5556
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5697
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3020
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.