Subject: Re: Trigger usecase

From: Laurenz Albe <[email-masked]>
Date: Tue, 30 Jul 2024 19:24:06 +0200

On Tue, 2024-07-30 at 20:46 +0530, sud wrote:
> Now while loading transactions data we also get some reference data information from
> source (for example customer information) and for these , we dont want to modify or
> override the existing customer data but want to keep the old data with a flag as
> inactive and the new record should get inserted with flag as active. So for such
> use case , should we cater this inside the apache flink application code or should
> we handle this using trigger on the table level which will execute on each INSERT
> and execute this logic? 
> 
> I understand trigger is difficult to debug and monitor stuff. But here in this case ,
> team mates is saying , we shouldn't put such code logic into a streaming application
> code so should rather handle through trigger. 
> 
> I understand, technically its possible bith the way, but want to understand experts
> opinion on this and pros ans cons?

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.

Yours,
Laurenz Albe

---

From: sud <[email-masked]>
Date: Wed, 31 Jul 2024 00:16:01 +0530

On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe <[email-masked]>
wrote:

> 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

---

From: Adrian Klaver <[email-masked]>
Date: Tue, 30 Jul 2024 11:50:48 -0700

On 7/30/24 11:46, sud wrote:
> 
> On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe <[email-masked] 
> <mailto:[email-masked]>> wrote:
> 
> 
> 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?
> 
> 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.

-- 
Adrian Klaver
[email-masked]

---

From: "David G. Johnston" <[email-masked]>
Date: Tue, 30 Jul 2024 13:28:35 -0700

> database procedure/functions. Hope this understanding correct.

That is my personal take.  For process-oriented stuff you can follow the
trail of calls all the way through to the end of the process and its final
result.  With triggers you follow the trail to the insert/update/delete
then stop thinking that's it, while in reality it continues because you
have triggers performing yet more work.

David J.