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 1sYrrZ-00Eewb-2x for pgsql-general@arkaria.postgresql.org; Tue, 30 Jul 2024 18:46:20 +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 1sYrrX-00CU61-8g for pgsql-general@arkaria.postgresql.org; Tue, 30 Jul 2024 18:46:19 +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 1sYrrW-00CU5s-SN for pgsql-general@lists.postgresql.org; Tue, 30 Jul 2024 18:46:18 +0000 Received: from mail-vs1-xe34.google.com ([2607:f8b0:4864:20::e34]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sYrrT-002Fcz-Nc for pgsql-general@lists.postgresql.org; Tue, 30 Jul 2024 18:46:17 +0000 Received: by mail-vs1-xe34.google.com with SMTP id ada2fe7eead31-4929540f38dso1315871137.2 for ; Tue, 30 Jul 2024 11:46:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722365175; x=1722969975; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=P4pZN/0bLPJPSbh3CwJdKeBL+LrN4CfIOEwIqKhZBIo=; b=W214/r/hxObsklogZo92ob51CpSDAXHLhTBkjsm3oXisy4ozX8QztyLEJcnL/cEPT1 yH0PtU8JsvrazI31vmLZ9W/71QQlIdO8WmBMPsHt3jmvdbya4IfBP7mf6KYiQcpKi4FC 8iV5lupL20kaTwXrmDN90T9eiQIw4Y38gv26aKAS1RDdUYCCe4hEbIXdUddktKf18QQG u+kq4c6aobnX2ZbJRMEbDe1mqs6Sxr5OlKJSvryl0JzlPt0dYYKd8W1FyZ8/mCCKK7Pz uadqKKCdATF6dc0PBuxgbYKBNjMcVb/A7FM2eUIWXlWmNKX8Qkyd2kOBjq7qWOezUSqb qXNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722365175; x=1722969975; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=P4pZN/0bLPJPSbh3CwJdKeBL+LrN4CfIOEwIqKhZBIo=; b=DCQC50PIrjtmTut/7nPz5c1sFzLXrCp/O+F/6EwrSNi0XaiRHvhc4KTt6U5yIttfEo M7pZXNedhOdNAwOeBcCE0j0+7weaao8EswB+s4H4TzleHaQNmy11ekV66LfF7gC0hIzq iDA7CDoKtjq9u/YCSaqAFpX1imE2arQwkCkYub7+pRz5KCS5zu+esvc9gm0UL8YKxTJs pwVfuoQ/O8NgDMKDzr7g0PzUIK9Q4vRsAULQ/CM0UDCZ5hjCfScE7zLjtFT6+Fmt4kH0 nLAvj8OFf+XgAfH3mMVNkoAV/3t/pyVkfY7mG0ahR10Ozk4yGJR8W0m8FaN8iz4TLeLX +JIg== X-Gm-Message-State: AOJu0YwFi+TwIdDBuHrZi3PwCtA1fXzRNYHFlbCLtw8mOPzvemKAjYhP tmJ0xCwLW5bm+akQwysUoNEU5Yh4ZvR7/NVaSxrwnjwt7amUgsb0r3+7n842NowiBRzAJda2UoP H+oZ+c2ZnVBH5WwHGxbZq3tCe7vU= X-Google-Smtp-Source: AGHT+IFUhLimYuoF+o9GfkoXqyzot5OJNDAWAYReaRRLkT2zumvuledls/HjBTUsUm08FPtTP2gHG+KbRZBIYQ41ntI= X-Received: by 2002:a05:6102:dc6:b0:48f:3df9:ff9 with SMTP id ada2fe7eead31-493fa19c8d9mr15485789137.8.1722365174705; Tue, 30 Jul 2024 11:46:14 -0700 (PDT) MIME-Version: 1.0 References: <85cc2eb0ca709ab753e618584f46dbf8801e9658.camel@cybertec.at> In-Reply-To: <85cc2eb0ca709ab753e618584f46dbf8801e9658.camel@cybertec.at> From: sud Date: Wed, 31 Jul 2024 00:16:01 +0530 Message-ID: Subject: Re: Trigger usecase To: Laurenz Albe , "David G. Johnston" Cc: pgsql-general Content-Type: multipart/alternative; boundary="000000000000697635061e7b64a0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000697635061e7b64a0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jul 30, 2024 at 10:54=E2=80=AFPM 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. Regards Sud --000000000000697635061e7b64a0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Tue, Jul 30, 2024 at 10:54=E2=80=AFPM = Laurenz Albe <laurenz.albe@c= ybertec.at> wrote:

It is largely a matter of taste.

The advantage of a trigger is that it works even if somebody bypasses the a= pplication
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 fin= e i believe, however=C2=A0this use case=C2=A0was to load/persist data in ta= ble with SCD-2 style, so is it good idea to use the trigger for such use ca= se?

Not sure of the exact pros and cons, but w= e were following certain rules like , if it's business logic which need= s to be implemented in Database, then it should not be done using triggers = but rather should be done through database procedure/functions. Hope this u= nderstanding=C2=A0correct.

Regards
Sud= =C2=A0
--000000000000697635061e7b64a0--