Search Postgresql Archives

FOREIGN KEY CONSTRAINT AND INHERITANCE

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux