Database Reference
In-Depth Information
CREATE TRIGGER notify_update_trigger
AFTER UPDATE ON notify_test
FOR EACH ROW
EXECUTE PROCEDURE notify_trigger();
CREATE TRIGGER notify_delete_trigger
AFTER DELETE ON notify_test
FOR EACH ROW
EXECUTE PROCEDURE notify_trigger();
Check if the preceding code works.
First, let's test the update trigger:
postgres=# update notify_test set i = i * 10;
NOTICE: Hi, I got notify_update_trigger
invoked FOR ROW AFTER UPDATE on notify_test
NOTICE: Hi, I got notify_update_trigger
invoked FOR ROW AFTER UPDATE on notify_test
UPDATE 2
Works fine—we get a notice for two invocations of our trigger function.
And now delete :
postgres=# delete from notify_test;
NOTICE: Hi, I got notify_delete_trigger
invoked FOR ROW AFTER DELETE on notify_test
NOTICE: Hi, I got notify_delete_trigger
invoked FOR ROW AFTER DELETE on notify_test
DELETE 2
If we only want to be notified each time an operation is performed on the table,
the preceding code is enough. One small improvement can be made in how we
define the triggers. Instead, of creating one trigger for each of INSERT , UPDATE , or
Search WWH ::




Custom Search