Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TPHGD-0006HA-7w for pgsql-sql@postgresql.org; Fri, 19 Oct 2012 18:25:29 +0000 Received: from nm11.bullet.mail.ac4.yahoo.com ([98.139.52.208]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TPHG6-0001x8-FB for pgsql-sql@postgresql.org; Fri, 19 Oct 2012 18:25:28 +0000 Received: from [98.139.52.194] by nm11.bullet.mail.ac4.yahoo.com with NNFMP; 19 Oct 2012 18:25:20 -0000 Received: from [76.13.13.47] by tm7.bullet.mail.ac4.yahoo.com with NNFMP; 19 Oct 2012 18:25:20 -0000 Received: from [127.0.0.1] by smtp108.prem.mail.ac4.yahoo.com with NNFMP; 19 Oct 2012 18:25:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1350671120; bh=ST3fHTPFLYLLbcmb/v/ABFuRIT6Vgm1JwAc6tcQFEh0=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=rA3z0TKAz94PBAQVAfOla3buoJDcq5tR05KyoYHsEXqXBsJjHrq6MI3gNecqNh7GtGgzANc7SdekWwMF469TBviZNiSskOtm0MNzzh7w+vKxySfaRWXWk0zJ3hKOKdJRP61NaHVJih4lYRJ09CM4gnFw2C/Cq154s61LvM8gvGw= X-Yahoo-Newman-Id: 389510.46269.bm@smtp108.prem.mail.ac4.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 1sTq_JYVM1lFystS4i8AFJTq0QEFBvK6II3JupZ.0YEE8z2 1gBPT6HJ4Emj5zAcgIr8X.94PYJWAhnkFv66RxCEbnbag_NMYSJVJ219jZf0 NFETOOlQGsnpg9qBZHG8dccU3O7YgrerYNPEbbE.nUKM0by6OweDXt2C5c0x mojkR8mHUoqE2xiinqy8WKedA3XMskVhkX4YxVfCUo8jdHEm.BP86L2lckyn XZyt5rpG2fIdWYe5p8uUajQwIEQPdfRKFErcvoqQB2aVuV66jFUlgQXHCyWN U5dd5WtL_T38zlnHglpLZj.0HFqZRolcKbBlHd6.oG.I.jxB4ZQfwsSnQXE5 .KtNwsmOzbE.YKnr2UVHqdT68iuLEVpBN9vJTCAdzg86VcaiL0skabKtgVn2 epzrNigEO5MJMrlLiDnVDPYU.TcJqhD.GvPtwcjWzFwyVGcZnZftXueaGkv4 csEGc X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp108.prem.mail.ac4.yahoo.com with SMTP; 19 Oct 2012 11:25:20 -0700 PDT From: "David Johnston" To: "'Victor Sterpu'" , References: <50819898.9090508@caido.ro> In-Reply-To: <50819898.9090508@caido.ro> Subject: Re: Trigger triggered from a foreign key Date: Fri, 19 Oct 2012 14:24:41 -0400 Message-ID: <032401cdae27$0199b2e0$04cd18a0$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQF9JM94cgM3S2edwbCnigQh6aVsKJhiAtmw Content-Language: en-us X-Pg-Spam-Score: -2.4 (--) X-Archive-Number: 201210/42 X-Sequence-Number: 36913 > -----Original Message----- > From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql- > owner@postgresql.org] On Behalf Of Victor Sterpu > Sent: Friday, October 19, 2012 2:15 PM > To: pgsql-sql@postgresql.org > Subject: [SQL] Trigger triggered from a foreign key > > I have this trigger that works fine. The trigger prevents the deletion of the > last record. > But I want skip this trigger execution when the delete is done from a external > key. > How can I do this? > I do not think this is possible; there is no "stack" context to examine to determine how a DELETE was issued. The trigger itself would seem to be possibly exhibit concurrency issues, meaning that in certain circumstances the last record could be deleted. You may want to add explicit locking to avoid that possibility. That or figure out a better way to accomplish whatever it is you are trying to do. David J.