rule as on insert to view with multiple fk referencing the same table

Поиск
Список
Период
Сортировка
От Joan Picanyol
Тема rule as on insert to view with multiple fk referencing the same table
Дата
Msg-id 20040316212222.GB17927@grummit.biaix.org
обсуждение исходный текст
Ответы Re: rule as on insert to view with multiple fk referencing the same table  (Joan Picanyol <lists-pgsql@biaix.org>)
Re: rule as on insert to view with multiple fk referencing the same table  (Enrico Weigelt <weigelt@metux.de>)
Список pgsql-general
Hi,

I have a schema which simplifies to the following:

create table a (id serial not null primary key, data int);
create table b (id serial not null primary key, data int\
    ref1 int references a not null, ref2 int references a not null,\
    ref3 int references a);
create view vw (data_a, data_b1, data_b2, data_b3) as select \
    (b.data as data_b, a1.data as data_a1, a2.data as data_a2,\
    a3.data as data_a3) from b, a a1, a a2, a a3 where b.ref1=a1.id\
    and b.ref2=a2.id and b.ref3=a3.id;

And now I want to create an insert rule into vw with all my foreign keys
properly set. I can't think of anything better that doing first the
three inserts into a and then use nextval()-1, nextval()-2 etc for the
fk values, but it looks really ugly (even though I could wrap up within
a BEGIN(...)COMMIT).

What's the 'canonical' way to do this?

tks
--
pica

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

Предыдущее
От: Josué Maldonado
Дата:
Сообщение: Lock inside trigger
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: fsync