Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVdku-0007Ay-ON for pgsql-general@arkaria.postgresql.org; Fri, 15 Nov 2019 15:43:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVdkr-0006Oo-A0 for pgsql-general@arkaria.postgresql.org; Fri, 15 Nov 2019 15:43:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVdkp-0006L6-4B for pgsql-general@lists.postgresql.org; Fri, 15 Nov 2019 15:43:25 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iVdkh-0006Mf-A9 for pgsql-general@postgresql.org; Fri, 15 Nov 2019 15:43:21 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id E149D631; Fri, 15 Nov 2019 10:43:12 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 15 Nov 2019 10:43:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=c cl3iJScshEPcF5Aeznyj6G8eiVsOFQ/CPGfNadoyoU=; b=20hM9P7iLzIAtXbOG r9khXuKATSq3XgOHJjB1Wjpsk71cNAitQmlf5dQdoXyq4UsJViRsKi1AWq0D7qFV GKBFnrNQSg3X5kpaoeGuq6L7ugTOOYjvdAUcBrFnS3/8ZEGONmmBJG8UkTBS6rGg 0k6UHhCRU1AXcJhQbiNyQioAKnVRGYvG5ijCTwQ0iJH5wSraVgVLZkiNxYIS2eoc 1MUlcFuc0uApNvLb+gToqU2dAbijgnkLRuytqq5pqOOfBlX4qBbKobeAf+kPoBUc ktxCAKQCtitNqyzZREjF5+D8jrXvpMLLM9mrQv46V7gabdFpkmi70Q8mRfx2b+/Y gi6Tw== 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-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=ccl3iJScshEPcF5Aeznyj6G8eiVsOFQ/CPGfNadoy oU=; b=OvW0fQgmtKLjdzSbS8I/zWfVn2+Fxzxphgk8vijv1XM+TVvKonPTQYzQv fOjpEoAb9MCWR/Nd3r0mrXQwLSqJr7RXWqxKNJV1JuRoubpYeaWcUFm8NxVhC1DT DxsbyMcHUo5TwEB3bUTKnqdCzf5PYjuiONoOYKVZBpyWbUCF5jPa5pq87z9vgrk7 idc94ACCNq6F2t3CaQqjd3je8dx5+yLQBKfsTooLlv5sHHs0UbR/LPY+imYK2D7h Jot0voShYKih55giAQRd7zxgG1QzHq1+R5yQV9nE7qU17m/mMDVISRUsEUphmZOq 7tZntcAvhGasW6Y9p8O0OX9gHAebg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrudefhedgkedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuffhomhgrihhnpehpohhsthhgrhgvsh hqlhdqrghrtghhihhvvgdrohhrghenucfkphepjedurddvuddvrddugeegrdejheenucfr rghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrh drtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.144.75]) by mail.messagingengine.com (Postfix) with ESMTPA id A58F68005C; Fri, 15 Nov 2019 10:43:11 -0500 (EST) Subject: Re: naming triggers for execution To: PegoraroF10 , pgsql-general@postgresql.org References: <1573828269057-0.post@n3.nabble.com> <1573830661749-0.post@n3.nabble.com> From: Adrian Klaver Message-ID: <79306433-e971-a80f-be28-2af6cb7314ee@aklaver.com> Date: Fri, 15 Nov 2019 07:43:10 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 In-Reply-To: <1573830661749-0.post@n3.nabble.com> 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 11/15/19 7:11 AM, PegoraroF10 wrote: > well, my way of doing auditing is done on replica, so it´s a little different > on production server I do on before update > > IF (tg_op = 'UPDATE') AND (new.* IS DISTINCT FROM old.*) THEN > new.userauditing = User_ID > new.datetimeauditing = current_timestamp; > END IF; > RETURN new; > > Then, on replica server I do > IF (tg_op = 'INSERT') THEN > insert into auditingtable .... with insert data > ELSIF (tg_op = 'UPDATE') AND (new.datetimeauditing IS DISTINCT FROM > old.datetimeauditing) THEN > insert into auditingtable .... with old and new data > ELSIF (tg_op = 'DELETE') THEN > insert into auditingtable .... with old data > END IF; > That trigger on replica is configured to run on replica with ENABLE REPLICA > TRIGGER > > With this approach I´m sure nothing will be audited if nothing was changed > and additionally all auditing will be done on replica which will frees the > production server for production and not auditing. > > But, independently of my auditing is being different from yours, what do you > do when you have two triggers using same event on same table. > Another example I can give you is when you define a PK. Imagine you have a > function which creates your PK, but another trigger needs that pk value to > do something. Both are ran before insert but trigger which creates PK needs > to be the first. How can you sure this happens. Back to your original post: "If multiple triggers of the same kind are defined for the same event, they will be fired in alphabetical order by name." Use appropriate naming or combine/nest the functions. > > > > -- > Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html > > > -- Adrian Klaver adrian.klaver@aklaver.com