Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-27 Thread Keary Suska
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

Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-26 Thread Tom Lane
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

[GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-25 Thread Rick Schumeyer
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

Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-25 Thread Bruce Momjian
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

Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-25 Thread Tom Lane
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

Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-25 Thread Rick Schumeyer
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

Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-25 Thread Rick Schumeyer
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]

Re: [GENERAL] Is this correct behavior for ON DELETE rule?

2005-02-25 Thread Bruce Momjian
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