Re: Inheritance and foreign keys

From: Andreas Kretschmer <andreas(at)a-kretschmer(dot)de>
To: pgsql-general(at)postgresql(dot)org,Jayadevan M <maymala(dot)jayadevan(at)gmail(dot)com>,"pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Inheritance and foreign keys
Date: 2017-05-25 12:10:00
Message-ID: 99566864-30E0-4AD0-BCCA-EABBC5ABFF42@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Not possible - yet.

Am 25. Mai 2017 13:48:59 MESZ schrieb Jayadevan M <maymala(dot)jayadevan(at)gmail(dot)com>:
>Hi,
>
>I designed three tables so that one table inherits another, and the
>third
>table references the parent table. If a record is inserted into the
>third
>table and the value does exist in the parent table indirectly, because
>it
>is present in the inherited table, I still get an error.
>Is some option available while creating the foreign key so that it will
>consider the data in the child tables also while doing a constraint
>validation?
>
>create table myt(id serial primary key);
>create table mytc (like myt);
>alter table mytc inherit myt;
>insert into myt values(1);
>insert into mytc values(2);
> select * from myt;
> id
>----
> 1
> 2
>
>create table a (id integer references myt(id));
>insert into a values(2);
>ERROR: insert or update on table "a" violates foreign key constraint
>"a_id_fkey"
>DETAIL: Key (id)=(2) is not present in table "myt".
>
>
>Regards,
>Jayadevan

--
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2017-05-25 12:30:39 Re: Inheritance and foreign keys
Previous Message Jayadevan M 2017-05-25 11:48:59 Inheritance and foreign keys