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 |
Thread: | |
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 | Date | Subject | |
---|---|---|---|
Next Message | Tormod Omholt-Jensen | 2006-03-27 11:32:33 | Converting a database from LATIN1 to UTF-8 |
Previous Message | Martijn van Oosterhout | 2006-03-27 11:13:20 | Re: What to index to speed up my UNION views? |