Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYrwA-00EfTa-EP for pgsql-general@arkaria.postgresql.org; Tue, 30 Jul 2024 18:51:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sYrw8-00CYdG-UY for pgsql-general@arkaria.postgresql.org; Tue, 30 Jul 2024 18:51:04 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYrw6-00CYXS-O2 for pgsql-general@lists.postgresql.org; Tue, 30 Jul 2024 18:51:04 +0000 Received: from fhigh1-smtp.messagingengine.com ([103.168.172.152]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sYrvx-002Ff3-Br for pgsql-general@lists.postgresql.org; Tue, 30 Jul 2024 18:51:00 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfhigh.nyi.internal (Postfix) with ESMTP id E29761140139; Tue, 30 Jul 2024 14:50:50 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 30 Jul 2024 14:50:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1722365450; x=1722451850; bh=s+ebG+AC9bAD7DP081aZO7kbKg0/ynfdo2VxS4sPT8c=; b= guFGaIHLWv2KHkacBkARTgDirADz1+FqxV3vMfouAdUCkrnu3LorCk2CF0jWUvOF CZpxh4DpTtQ1V6mlSofZrsneP1sjVJmLX01UtrDGmGmH5UprJqzckFtcx8YCrcR7 8HNcxG3iXQ+afvUqos9Si0iPy5RL2so0I6N1+Ohwhy5cnD8DnPQXiweQSvgMKB3d Kqm2ifoOFyGbqOLr1XPmtJVo9RPqkLKVAJAQWzPMyjY7nTsd/UfQSyUATc43cj8K 3Jc9a9GgNixGDVRKCgSUPa4kJ0pNgHNsvHt5FmhvJRP/ehxufp+2Tye6zMbBZq8p Uwu8FexiNw2XDycNxnXMUg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1722365450; x= 1722451850; bh=s+ebG+AC9bAD7DP081aZO7kbKg0/ynfdo2VxS4sPT8c=; b=S hLUzJcaVky7fhQ35GR0TRbw18bGrs3CtifZQ97pGiZobuHqp2fsFIgHaESqi5cR6 KK0VtrL0w8oSPyZwx9NcTaNHiX0pS/R92MAqYQyx37JrSH2x6JwOIOrkDM7eCK8h rF5n6qY8dpdF8mssfWahaiphPu6NQyiCQRV+ZwEZxsQne1Z0wKEAWz2w6YO1upHG J5y/ulhLD2HubilhnUPuj46sYo+/5sGRf6zOC8oJCB4lwQyZ6q6mmFXP466ZZKXZ ofPTBQi8Dlly4fxvUKfdM2VRZkLilxZh6fO8dXt7O2yjgHWgs7ZhT++jxGrNWa2W JsnlcJVRQxgPgz4p4Dk6Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrjeeggddufedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuggftrfgrthhtvghrnhepfeegfeeiuedtgffgteeggfehkeejheetieeliefg teeikeejvdeiveeigfehvedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhdp nhgspghrtghpthhtoheptd X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 30 Jul 2024 14:50:49 -0400 (EDT) Message-ID: <08b3b796-3165-4104-a250-b1c6387cf98d@aklaver.com> Date: Tue, 30 Jul 2024 11:50:48 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Trigger usecase To: sud , Laurenz Albe , "David G. Johnston" Cc: pgsql-general References: <85cc2eb0ca709ab753e618584f46dbf8801e9658.camel@cybertec.at> Content-Language: en-US From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/30/24 11:46, sud wrote: > > On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe > wrote: > > > It is largely a matter of taste. > > The advantage of a trigger is that it works even if somebody > bypasses the application > to insert data. > > I think that triggers are easy to debug, but again, that's a matter > of taste. > > > Thank you David and Laurenz. > > Creating triggers to populates some audit table or say populating data > in audit columns (created_by, updated_by,created_date,updated_date) is > fine i believe, however this use case was to load/persist data in table > with SCD-2 style, so is it good idea to use the trigger for such use case? > > Not sure of the exact pros and cons, but we were following certain rules > like , if it's business logic which needs to be implemented in Database, > then it should not be done using triggers but rather should be done > through database procedure/functions. Hope this understanding correct. Triggers have to use procedures/functions so I am not understanding the issue. > > Regards > Sud -- Adrian Klaver adrian.klaver@aklaver.com