FOREIGN KEY CONSTRAINT AND INHERITANCE - Mailing list pgsql-general

From Sergey Karin
Subject FOREIGN KEY CONSTRAINT AND INHERITANCE
Date
Msg-id b78883bf0704250825r49e48803v30d498a9a1cbeeeb@mail.gmail.com
Whole thread Raw
Responses Re: FOREIGN KEY CONSTRAINT AND INHERITANCE  ("A. Kretschmer" <andreas.kretschmer@schollglas.com>)
List pgsql-general
Hi, All!

I have the tables as defined:

create table style
(
   ID_STYLE             INT4 not null,
   STYLE_STRING         VARCHAR              not null,
   constraint PK_STYLE primary key (ID_STYLE)
);

create table style_type_object
(
   ID_TYPE_OBJECT       INT4                 not null,
   ID_STYLE             INT4                 not null,
   ZOOMABLE             BOOL                 not null default false,
   START_SCALE          INT4                 not null,
   END_SCALE            INT4                 not null
);

alter table STYLE_TYPE_OBJECT
   add constraint FK_ID_STYLE foreign key (ID_STYLE)
      references STYLE (ID_STYLE)
      on delete restrict on update restrict;

create table style_1
(
    constraint PK_STYLE_1 primary key (id_style),
    check (id_style between 1 and 10000)
) inherits (style);


create rule r_style_1 as on insert to style
where (id_style between 1 and 10000)
do instead
      insert into style_1 (id_style, style_string)
      values(new.id_style, new.style_string);


insert into style values (2,  'PEN(w:1px)' );

vka7=# select id_style, style_string from style;
 id_style | style_string
----------+--------------
        2 | PEN(w:1px)


vka7=# insert into style_type_object values(1, 2, false, 0, 0);
ERROR:  insert or update on table "style_type_object" violates foreign key constraint "fk_id_style"
DETAIL:  Key (id_style)=(2) is not present in table "style".


THE QUESTION IS: are there any abilities to check foreign key constraint not only in master table, but also in all tables that inherited the master?

Thanks in advance.

Sergey Karin

pgsql-general by date:

Previous
From: "sangeetha k.s"
Date:
Subject: reg: bitmap index implementation
Next
From: "Simon Riggs"
Date:
Subject: Re: Regarding WAL