patternsqlModerate
Check what event called the trigger on PostgreSQL?
Viewed 0 times
postgresqlcalledthetriggerwhatcheckevent
Problem
I'm trying to check what event called my trigger, like
Oracle triggers can check this in a simple 'IF' statement:
Is there a similar statement on PostgreSQL?
Usually I just create a function for
Can someone help?
INSERT, UPDATE or DELETE.Oracle triggers can check this in a simple 'IF' statement:
IF INSERTING, IF UPDATING or even IF DELETINGIs there a similar statement on PostgreSQL?
Usually I just create a function for
INSERT, an other one for UPDATE and one more for DELETE, but it's a waste of code if there's some way to create just one function.Can someone help?
Solution
Trigger functions can check the value of the
TG_OP variable to determine the event which caused the trigger to fire. There are a number of other special variables as well listed in the documentation.Context
StackExchange Database Administrators Q#27720, answer score: 10
Revisions (0)
No revisions yet.