Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id B275B1337B77 for ; Thu, 2 Dec 2010 23:52:20 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 26115-04 for ; Fri, 3 Dec 2010 03:52:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 713711337B6F for ; Thu, 2 Dec 2010 23:52:13 -0400 (AST) 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 oB33qBKC015327; Thu, 2 Dec 2010 22:52:11 -0500 (EST) To: Konstantin Nikiforov cc: pgsql-bugs@postgresql.org Subject: Re: Bug: table inheritance. Trigger before DELETE for each statement is ignored In-reply-to: <20101202232343.02f9246c@alkaida> References: <20101202232343.02f9246c@alkaida> Comments: In-reply-to Konstantin Nikiforov message dated "Thu, 02 Dec 2010 23:23:43 +0300" Date: Thu, 02 Dec 2010 22:52:11 -0500 Message-ID: <15326.1291348331@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201012/8 X-Sequence-Number: 28814 Konstantin Nikiforov writes: > Expected result: exception will be raised before deletion of rows is > done. > Real result: no exception occurs. One of rows is really deleted. > The trigger is ignored. I believe this is intentional, though not too well documented. If we fired statement triggers on child tables, then we'd have to fire all such triggers, potentially on hundreds of child tables. In particular this would result in a problem for constraint exclusion: discarding child tables that couldn't be referenced by the query action would result in a visible change in behavior. So the designed behavior is that only the named target table has its statement triggers fired. > 1. You can uncomment INSERT statement, and try again: exception > will be thrown. BEFORE INSERT works, BEFORE delete - no. The reason the INSERT case works is you're naming the child table as target. > 2. If i create trigger FOR EACH STATEMENT, it will work ok for insert, > update and delete. You mean FOR EACH ROW, no? regards, tom lane