You can consider a rule as transforming the command being executed, whereas a trigger is altering the data itself. (Note that this is a simplification! Spend some time reading the documentation for CREATE TRIGGER
and CREATE RULE
rather than trusting some random internet guy.)
So you can define a rule that triggersis invoked when PostgreSQL sees a certain command, and transforms that command into something that would not invoke the trigger.
Take for instance a rule defined as such:
CREATE OR REPLACE RULE dont_insert AS
ON INSERT TO xyz.items
DO INSTEAD NOTHING;
And a trigger defined as such:
CREATE TRIGGER insert_with_func BEFORE INSERT
ON xyz.items FOR EACH ROW
EXECUTE PROCEDURE xyz.row_update_func();
Attempting to do an insert will not invoke row_update_func()
, even if the trigger is defined as BEFORE INSERT
, because the rule is modifying the command itself; after the command is re-evaluated, it's no longer doing anything, and the trigger no longer applies.
Obviously your rule does not need to be defined with INSTEAD OF
, and in that case, your rule and your trigger could both apply.
With specific regard to your code, it's hard to say without knowing the definition of konto_zwrocone
, but it doesn't look like it since your trigger and rule are defined for different operations on different tables.