on 2/25/05 4:09 PM, [EMAIL PROTECTED] purportedly said:
I have two related tables, ³item² and ³book². I have defined
a view, ³bookview² that contains fields from item and book.
My goal was to have all inserts, updates, and deletes performed
on bookview rather than on the tables directly. I
Rick Schumeyer [EMAIL PROTECTED] writes:
Would some combination of triggers work instead?
Nope, you can't put triggers on a view, sorry. In theory a BEFORE
INSERT trigger would be a workable alternative to an ON INSERT rule
for redirecting insertions. (I think we disallow it at the moment
I have two related tables, item
and book. I have defined
a view, bookview
that contains fields from item and book.
My goal was to have all
inserts, updates, and deletes performed
on bookview rather than on
the tables directly. I was able
to do this with ON INSERT
and ON UPDATE rules
Uh, because of your REFERENCES clause you have to delete from 'item'
first, then 'book':
-- delete to item and book instead of bookview
create rule bookviewdel as on delete to bookview do instead (
delete from item where id=old.id;
delete from book where id=old.id;
);
And your
Rick Schumeyer [EMAIL PROTECTED] writes:
-- delete to item and book instead of bookview
create rule bookviewdel as on delete to bookview do instead (
delete from book where id=old.id;
delete from item where id=old.id;
);
This is an ancient gotcha: as soon as you delete the book
I suspected that might be part of the answer.
Would some combination of triggers work instead? I've played
with those too, but without success.
This is an ancient gotcha: as soon as you delete the book row, there is
no longer any such entry in the bookview view ... and old.id is
I tried that, but I get a ...violates foreign-key constraint error.
-Original Message-
From: [EMAIL PROTECTED] [mailto:pgsql-general-
[EMAIL PROTECTED] On Behalf Of Bruce Momjian
Sent: Friday, February 25, 2005 6:23 PM
To: Rick Schumeyer
Cc: 'PgSql General'
Subject: Re: [GENERAL]
Rick Schumeyer wrote:
I tried that, but I get a ...violates foreign-key constraint error.
Oh, sorry.
---
-Original Message-
From: [EMAIL PROTECTED] [mailto:pgsql-general-
[EMAIL PROTECTED] On Behalf Of