FOREIGN KEY CONSTRAINT AND INHERITANCE

From: "Sergey Karin" <sergey(dot)karin(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: FOREIGN KEY CONSTRAINT AND INHERITANCE
Date: 2007-04-25 15:25:46
Message-ID: b78883bf0704250825r49e48803v30d498a9a1cbeeeb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message sangeetha k.s 2007-04-25 15:35:54 reg:bitmap index
Previous Message Simon Riggs 2007-04-25 15:24:05 Re: [GENERAL] Regarding WAL