473,513 Members | 2,658 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Discussion about inheritance

Hello,

I'm using inheritance in my DB with PostgreSQL 7.3.4, and a friend of my
told me that there is a bug in that type of table.

To resume, the problem is:
- a table A have a primary key
- a table B references the primary key of A
- a table C inherits the A fields
- when I insert a tuple in table B that references something inserted at
A, everything is OK.
- when I insert a tuple in table B that references something inserted at
C, a integrity violation occurs.

To me, this looks not like a bug, because the tuple is not at A phisically.

Taking the example of a VIEW: its not possible to reference a column in a
view because the data is not phisically in it.

Here, i put an example where i try to show the "problem" (it is in
portuguese, but I think the names don't seem to be a problem for all):
PostgreSQL 7.3.4

everton=# create table pessoa (id_pessoa serial NOT NULL PRIMARY KEY,
nome character varying(30));

everton=# create table pessoafisica(cpf integer) INHERITS(pessoa);

everton=# create table pessoajuridica(cnpj integer) INHERITS(pessoa);

everton=# create table telefone(id_pessoa integer, telefone integer,
foreign key (id_pessoa) references pessoa (id_pessoa));

everton=# insert into pessoa(nome) values ('Everton');

everton=# insert into pessoafisica(nome, cpf) values ('Alencar', 123);

everton=# insert into pessoajuridica(nome, cnpj) values ('Philler', 999);

everton=# select * from pessoafisica;
id_pessoa | nome | cpf
-----------+---------+-----
3 | Alencar | 123

everton=# select * from pessoajuridica;
id_pessoa | nome | cnpj
-----------+---------+------
4 | Philler | 999

everton=# select * from pessoa;
id_pessoa | nome
-----------+---------
2 | Everton
3 | Alencar
4 | Philler

everton=# insert into telefone(id_pessoa, telefone) values (2, 5410000);
INSERT 22234 1
everton=# insert into telefone(id_pessoa, telefone) values (4, 5413443); ERROR: $1 referential integrity violation - key referenced from
telefone not found in pessoa


Like I said, this is not a problem for me, but I want to know if someone
thinks this can be considered a real problem, or if something will be done
to try to correct (or modify) this operation.

Thanks to all,

Marcelo Soares
Informática - Master Hotéis
ICQ Externo: 19398317
ICQ Interno: 1002
Linux user#: 288006

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #1
1 1333
"Marcelo Soares" <ms*****@masterhoteis.com.br> writes:
To me, this looks not like a bug, because the tuple is not at A phisically.
A lot of people call it a bug because it makes it impossible for them to
use inheritance the way they want to.
Like I said, this is not a problem for me, but I want to know if someone
thinks this can be considered a real problem, or if something will be done
to try to correct (or modify) this operation.


It is likely that it will get changed at some point in the future,
because the consensus seems to be that the other behavior would be more
useful. However, fixing it seems to require building indexes across
multiple tables --- or else a drastic change in the storage
representation of inherited tables --- so it won't happen soon.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #2

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

Similar topics

11
3226
by: Ricky Romaya | last post by:
Hi, Are there any ways to get multiple inheritace in PHP4? For example, I have 3 parent class, class A, B, and C. I want class X to inherit all those 3 classes. Consider merging those 3 classes...
2
4361
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...
2
4321
by: Graham Banks | last post by:
Does using multiple inheritance introduce any more performance overhead than single inheritance?
4
2881
by: JKop | last post by:
I'm starting to think that whenever you derive one class from another, that you should use virtual inheritance *all* the time, unless you have an explicit reason not to. I'm even thinking that...
5
2166
by: Morgan Cheng | last post by:
It seems no pattern defined by GoF takes advantage of multiple inheritance. I am wondering if there is a situation where multiple inheritance is a necessary solution. When coding in C++, should...
22
23319
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...
2
1415
by: George Durzi | last post by:
I'd like to get some real world feedback from developers out there who have to work with the "design" folks to integrate look and feel stuff into a vs.net web project. A lot of designers use web...
5
3001
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
6
3798
by: Bart Simpson | last post by:
I remember reading on parashift recently, that "Composition is for code reuse, inheritance is for flexibility" see (http://www.parashift.com/c++-faq-lite/smalltalk.html#faq-30.4) This confused...
0
7257
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
7379
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
5682
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
4745
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...
0
3232
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
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1591
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 ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
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...

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.