Re: Partitioning/inherited tables vs FKs

Поиск
Список
Период
Сортировка
От Jaime Casanova
Тема Re: Partitioning/inherited tables vs FKs
Дата
Msg-id v2i3073cc9b1005060337x4883e16ak8e6bdf1996a29ffe@mail.gmail.com
обсуждение исходный текст
Ответ на Partitioning/inherited tables vs FKs  (Boszormenyi Zoltan <zb@cybertec.at>)
Ответы Re: Partitioning/inherited tables vs FKs  (Robert Haas <robertmhaas@gmail.com>)
Список pgsql-hackers
2010/5/6 Boszormenyi Zoltan <zb@cybertec.at>:
>
> =# insert into refer (parent_id) values (1);
> ERROR:  insert or update on table "refer" violates foreign key
> constraint "refer_parent_id_fkey"
> DETAIL:  Key (parent_id)=(1) is not present in table "parent".
>
> The use case for this was there were different news items,
> and there were another table for summaries, that could point
> to any of the news items table. Another use case could be
> a large partitioned table with an FK to the main table where
> the referring table might only contain very few "interesting" data.
>
> No matter what are the semantics, the parent table in the
> inheritance chain cannot be used as and endpoint for FKs.
>
> Is it a bug, or intentional?

i would call it a bug, but this is a known issue

>
> The only solution currently is that the referring table has to be
> partitioned the same way as the referred table in the FK, and
> its parent table has to be queried.
>

no, you can install a trigger on the child table that verifies the
existence of the id on your partitioned parent table, the SELECT
you'll use inside that trigger will look at the entire set of tables
(as long as you don't use FROM ONLY)

also could be useful to put an index (even a PK) on every child to
ensure uniqueness and make the SELECT more efficient, and of course a
check constraint in every child emulating a partition key

--
Jaime Casanova         www.2ndQuadrant.com
Soporte y capacitación de PostgreSQL


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: LD_LIBRARY_PATH versus rpath
Следующее
От: Simon Riggs
Дата:
Сообщение: Re: max_standby_delay considered harmful