public inbox for [email protected]
help / color / mirror / Atom feedRe: Trigger usecase
4+ messages / 4 participants
[nested] [flat]
* Re: Trigger usecase
@ 2024-07-30 17:24 Laurenz Albe <[email protected]>
2024-07-30 18:46 ` Re: Trigger usecase sud <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Laurenz Albe @ 2024-07-30 17:24 UTC (permalink / raw)
To: sud <[email protected]>; pgsql-general <[email protected]>
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Trigger usecase
2024-07-30 17:24 Re: Trigger usecase Laurenz Albe <[email protected]>
@ 2024-07-30 18:46 ` sud <[email protected]>
2024-07-30 18:50 ` Re: Trigger usecase Adrian Klaver <[email protected]>
2024-07-30 20:28 ` Re: Trigger usecase David G. Johnston <[email protected]>
0 siblings, 2 replies; 4+ messages in thread
From: sud @ 2024-07-30 18:46 UTC (permalink / raw)
To: Laurenz Albe <[email protected]>; David G. Johnston <[email protected]>; +Cc: pgsql-general <[email protected]>
On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe <[email protected]>
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Trigger usecase
2024-07-30 17:24 Re: Trigger usecase Laurenz Albe <[email protected]>
2024-07-30 18:46 ` Re: Trigger usecase sud <[email protected]>
@ 2024-07-30 18:50 ` Adrian Klaver <[email protected]>
1 sibling, 0 replies; 4+ messages in thread
From: Adrian Klaver @ 2024-07-30 18:50 UTC (permalink / raw)
To: sud <[email protected]>; Laurenz Albe <[email protected]>; David G. Johnston <[email protected]>; +Cc: pgsql-general <[email protected]>
On 7/30/24 11:46, sud wrote:
>
> On Tue, Jul 30, 2024 at 10:54 PM Laurenz Albe <[email protected]
> <mailto:[email protected]>> 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
[email protected]
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Trigger usecase
2024-07-30 17:24 Re: Trigger usecase Laurenz Albe <[email protected]>
2024-07-30 18:46 ` Re: Trigger usecase sud <[email protected]>
@ 2024-07-30 20:28 ` David G. Johnston <[email protected]>
1 sibling, 0 replies; 4+ messages in thread
From: David G. Johnston @ 2024-07-30 20:28 UTC (permalink / raw)
To: sud <[email protected]>; +Cc: Laurenz Albe <[email protected]>; pgsql-general <[email protected]>
On Tue, Jul 30, 2024 at 11:46 AM sud <[email protected]> wrote:
>
> 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.
>
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.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2024-07-30 20:28 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-07-30 17:24 Re: Trigger usecase Laurenz Albe <[email protected]>
2024-07-30 18:46 ` sud <[email protected]>
2024-07-30 18:50 ` Adrian Klaver <[email protected]>
2024-07-30 20:28 ` David G. Johnston <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox