Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdJ4K-00023g-MG for pgsql-general@arkaria.postgresql.org; Wed, 11 Jul 2018 17:38:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fdJ4I-0001zN-Am for pgsql-general@arkaria.postgresql.org; Wed, 11 Jul 2018 17:38:22 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdJ4H-0001yy-4h for pgsql-general@lists.postgresql.org; Wed, 11 Jul 2018 17:38:22 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fdJ4E-0000Ab-2I for pgsql-general@postgresql.org; Wed, 11 Jul 2018 17:38:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id B424E21C76; Wed, 11 Jul 2018 13:38:16 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 11 Jul 2018 13:38:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=zcuQLlX6qIsQXTsr6woS3y/yoBkuS Uv6OCD3io2bBcw=; b=GkZz2Vltt3o6cbpdxnr9R6QeVsK4onSqIhDUQmH3aVX3Z giGGkEdiMZZBMY8OfGNsCnUX1m3YohVvThvDKLYEuBZck8iqapanfVDva7pgx8GE Awq/lS7cOYuGJpoA+W9G7Nb40Occi+x/EY0mVzENwg4op8D465tMkY9sV1U5Hk8D rZP1WmP5YC2WYtHjjKRJ24hKi09DL/gcYzUGXcKmEl+kUe+y4U9DK8TVs6qJslYy OgrEUGy/3dY7f8GLjvoMV12PQzKj3q7pWahcJrWB0aMl6Bxp1fUA1PQ62btuARxn fUwNnuzxHAqlHK77fU9bPNLb/yO6lBcLzlRC/7kqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=zcuQLl X6qIsQXTsr6woS3y/yoBkuSUv6OCD3io2bBcw=; b=VzSz/Y1WhgrbhgEITqdiez oe2C29JJcSO1Zlsk9bnr9VyPb8iqt53zHCV/o+Oqw1QeBpGT8d5ruIHVBwHbY0r0 Rj+l4KNDfm4w9sPcnBiJCjex1cbasYbRf0E7ohDtGFlVHEMsjSJaauRR7aHOl16F yyN78VNgs4j6m2D8shAJtdX7RgHNnk/iB9UTImr4Q5586QDvWdehtQnzhZoeqPpJ c5zCR62K5khaDGWe/dfQXOBSyDYl9j12N9wOlzuFYuVw8qnvD8sj+gHIjFyF5MjK Z+9rz4ha3SkfELtQUUiVfDjjj1Gozm8vOs8GRFZj7pMCXGf7Ra/PW8tBYbYzj1Sg == X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.3] (unknown [71.212.134.181]) by mail.messagingengine.com (Postfix) with ESMTPA id DA82F10273; Wed, 11 Jul 2018 13:38:15 -0400 (EDT) Subject: Re: How to tell which event was fired in Trigger function To: "Igal @ Lucee.org" , pgsql-general References: From: Adrian Klaver Message-ID: <4fb09bff-b6db-e889-b4f0-9839bce44100@aklaver.com> Date: Wed, 11 Jul 2018 10:38:14 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 07/11/2018 10:36 AM, Igal @ Lucee.org wrote: > Hi, > > I am writing a trigger function that is used after DELETE, INSERT, and > UPDATE, like so: > >     CREATE TRIGGER tr_name AFTER DELETE OR INSERT OR UPDATE ... > > How can I tell inside the trigger function if the event was DELETE or > INSERT/UPDATE? > > The table has a `NOT NULL id` column, so I am thinking that maybe a > DELETE will have a NULL value in NEW.id?  Will that work?  Is there a > better way? https://www.postgresql.org/docs/10/static/plpgsql-trigger.html > > Thanks, > > Igal Sapir > Lucee Core Developer > Lucee.org > -- Adrian Klaver adrian.klaver@aklaver.com