Lists: | pgsql-general |
---|
From: | Paolo Sala <piviul(at)riminilug(dot)it> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Inheritance |
Date: | 2006-03-27 11:18:37 |
Message-ID: | 4427CA0D.4090204@riminilug.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hi, I'm new on postgres and I've just installed postgres 7.4.7 on a
debian sarge. I'm interested on using inheritance. I've tried a simple code:
CREATE TABLE t_main (
id serial primary key
);
CREATE TABLE t_derived1 (
field1 varchar(128) default NULL
) INHERITS (t_main);
Now I have to create another table having a field having a reference to
t_derived1. If I use the code
CREATE TABLE t_table1 (
id serial primary key,
id_derived1 int references t_derived1
);
I got an error: t_derived1 have no primary key... and in effect is
t_main that have the primary key... So I modified the code in
CREATE TABLE t_table1 (
id serial primary key,
id_derived1 int references t_main
);
and now all seems to work so I inserted a record on t_derived1
INSERT INTO t_derived1
(field1) VALUES ('field1 content of derived1 table');
and a record in t_table1 that have a reference to the record I've just
inserted:
INSERT INTO t_table1
(id_derived1) VALUES (1);
but I've got the error 'ERROR: insert or update on table "t_table1"
violates foreign key constraint "$1"
DETAIL: Key (id_derived1)=(1) is not present in table "t_main".'
So I ask you: there is a way to reference a record to an hinherited table?
Thank you very much
Piviul
From: | Paolo Sala <piviul(at)riminilug(dot)it> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Inheritance |
Date: | 2006-03-28 07:45:55 |
Message-ID: | 4428E9B3.3030608@riminilug.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Jebus scrisse in data 03/27/06 19:03:
>I could be wrong but primary keys and other constraints are not inherited.
>
>
Thank you very much Jebus; in effect I've found in the mailing list
archives a 2003 thread "INHERITS and Foreign keys" that claim the same
problem. Someone (Stephan Szabo) answered saying that "At some point in
the future, that's likely to change"
(http://archives.postgresql.org/pgsql-sql/2003-12/msg00101.php). Now I'm
using postgres 7.4.7 and I've found the same problem; do you know if
this problem is solved in postgres 8.1?
Thank you very much
Piviul
From: | Richard Broersma Jr <rabroersma(at)yahoo(dot)com> |
---|---|
To: | Paolo Sala <piviul(at)riminilug(dot)it>, pgsql-general(at)postgresql(dot)org |
Subject: | Re: Inheritance |
Date: | 2006-03-28 13:18:53 |
Message-ID: | 20060328131853.3055.qmail@web31808.mail.mud.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
> Jebus scrisse in data 03/27/06 19:03:
>
> >I could be wrong but primary keys and other constraints are not inherited.
do you know if
> this problem is solved in postgres 8.1?
No it isn't. But I remember reading on one of the lists that it was on the to-do list for 8.2.
However, I do not know how high it is on the list of things to do. So I imagine that there is the
potential that it might not be added.
Regards,
Richard Broersma Jr.
From: | Paolo Sala <piviul(at)riminilug(dot)it> |
---|---|
To: | |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Inheritance |
Date: | 2006-03-28 15:43:49 |
Message-ID: | 442959B5.3040703@riminilug.it |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Richard Broersma Jr scrisse in data 03/28/06 15:18:
>No it isn't. But I remember reading on one of the lists that it was on the to-do list for 8.2.
>However, I do not know how high it is on the list of things to do. So I imagine that there is the
>potential that it might not be added.
>
I'll wait 8.2 or 8.3.
Thank you very much.
Piviul