Re: INHERIT and FOREIGN KEY issues

Поиск
Список
Период
Сортировка
От Daniel Staal
Тема Re: INHERIT and FOREIGN KEY issues
Дата
Msg-id 113DE1B763DA6A393D81B013@Mac-Pro.magehandbook.com
обсуждение исходный текст
Ответ на INHERIT and FOREIGN KEY issues  (Luiz Eduardo Cantanhede Neri <lecneri@gmail.com>)
Список pgsql-novice
--As of May 24, 2009 2:54:47 PM -0300, Luiz Eduardo Cantanhede Neri is
alleged to have said:

> CREATE TABLE A
> (
> idA serial not null primary key,
> someColumn text
> );
>
> CREATE TABLE B
> (
> someData text
> ) INHERITS(A);
...
> CREATE TABLE BC(
> idB int4,
> idC int4,
>  FOREIGN KEY (idB) REFERENCES B(idA),
>  FOREIGN KEY (idC) REFERENCES C(idC)
> );
..
> But When it is going to create the table BC, it gives an error:
>
> ERROR:  there is no unique constraint matching given keys for referenced
> table "b"
>
> My question is: Shouldn't it get Table A primary key and create the
> foreign key?

--As for the rest, it is mine.

Perhaps it should, but it doesn't: Primary Keys are not inherited.  From
the docs (emphasis by me):

> All check constraints and not-null constraints on a parent table are
> automatically inherited by its children. Other types of constraints
> (unique, *primary key*, and foreign key constraints) are not inherited.

You'll want to put in an 'ALTER TABLE B ADD PRIMARY KEY("idA");' in there.

Daniel T. Staal

---------------------------------------------------------------
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---------------------------------------------------------------

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

Предыдущее
От: Luiz Eduardo Cantanhede Neri
Дата:
Сообщение: INHERIT and FOREIGN KEY issues
Следующее
От: Kedar Rasik Parikh
Дата:
Сообщение: Re: INHERIT and FOREIGN KEY issues