Обсуждение: Inheritance
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
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
> 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.
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