Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 6FAFD1DB6346 for ; Mon, 7 May 2012 12:06:24 -0300 (ADT) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SRPW3-0001Jv-4p for pgsql-bugs@postgresql.org; Mon, 07 May 2012 15:06:24 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q47F6AnT026031; Mon, 7 May 2012 11:06:10 -0400 (EDT) To: ignas@pow.lt cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6632: "before delete" triggers that delete rows from the same table can invalidate constraints In-reply-to: References: Comments: In-reply-to ignas@pow.lt message dated "Mon, 07 May 2012 13:49:05 -0000" Date: Mon, 07 May 2012 11:06:10 -0400 Message-ID: <26030.1336403170@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201205/33 X-Sequence-Number: 33004 ignas@pow.lt writes: > [ you can sabotage foreign key constraints with triggers ] This is not a bug, it's a "don't do that" issue. The only way to prevent it would be to not fire triggers during FK operations, or to somehow restrict what triggers are allowed to do, and either of those cures would be worse than the disease. In general, it's bad design to use a BEFORE trigger to propagate changes to other rows; you should do that in AFTER triggers. See the documentation. regards, tom lane