Re: Foreign Key Constraint Deletion Order
От | |
---|---|
Тема | Re: Foreign Key Constraint Deletion Order |
Дата | |
Msg-id | 200111190717.3b63@lh00.opsion.fr обсуждение исходный текст |
Ответ на | Foreign Key Constraint Deletion Order (<cnliou@eurosport.com>) |
Ответы |
Re: Foreign Key Constraint Deletion Order
|
Список | pgsql-sql |
Thanks! Stephan, > We've been having discussions on hackers about the behavior, > but it's unlikely that the rows will be deleted before > the master row. Then I am in big big trouble! Please imagine a very usual scenario: create table PurchaseMaster (book text primary key, UnitPrice float); create table PurchaseDetail ( CONSTRAINT fk_abc FOREIGN KEY (book) REFERENCES PurchaseMaster (book) on delete cascade on update cascade, primary key (book,buyer), book text, buyer text, quantity smallint ); create table HowMuchIOwe (buyer text primary key,amount float); CREATE FUNCTION MyTrigger() RETURNS opaque AS ' BEGIN UPDATE HowMuchIOwe set amount=amount-old.quantity*(select UnitPrice from PurchaseMaster where book=old.book) where buyer=old.buyer; END; CREATE TRIGGER TriggerDetail AFTER DELETE ON PurchaseDetail FOR EACH ROW EXECUTE PROCEDURE MyTrigger( ); Now when a row in PurchaseMaster is deleted by user, because: (1) getting rid of fk_abc constraint and replacing it with a custom trigger function associated with PurchaseMaster in order to delete PurchaseDetail "manually" does not work either since PurchaseMaster row may be deleted BEFORE this custom trigger function is called; (2) and row in PurchaseMaster may be deleted before PurchaseDetail. so I have no way out! CN -------------------------------------------------------- You too can have your own email address from Eurosport. http://www.eurosport.com
В списке pgsql-sql по дате отправления: