Inheritance

Поиск
Список
Период
Сортировка
От Paolo Sala
Тема Inheritance
Дата
Msg-id 4427CA0D.4090204@riminilug.it
обсуждение исходный текст
Список 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




В списке pgsql-general по дате отправления:

Предыдущее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: What to index to speed up my UNION views?
Следующее
От: Tormod Omholt-Jensen
Дата:
Сообщение: Converting a database from LATIN1 to UTF-8