I would like to ask you which are the RDBMS's which support multiple triggers for the same event. For instance I have a table called MyTable and I would like to create trigger1 and trigger2 which should run before insert into the given table. Is there an RDBMS which supports this?
Why do you need two triggers on the same "before insert" event? Can't you combine the trigger code into one?
Related
I am about to implement an audit system in my database and am looking for the most effective way to do this.
I've read the wiki and did my research.
There is this example: https://wiki.postgresql.org/wiki/Audit_trigger
And also this: https://wiki.postgresql.org/wiki/Audit_trigger_91plus
In the listed examples you have to create a trigger for each table (kinda redudant).
However with Postgres 9.3+ we have the ability of event triggers where we can react on special events like create, alter or drop table.
An optimal solution would be:
create event trigger UpdateTables
on ddl_command_end
when tag in ( 'insert ', 'update ')
execute procedure DoAudit();
However that returns:
ERROR: filter value "insert " not recognized for filter variable "tag"
SQL Status:42601
I am wondering if we also can react on insert, update events with event triggers and use this single trigger for all auditing?
This won't work.
The "on ddl_command_end" means the event is intended to be invoked on structural changes in the database. The complete reference to events is here: https://www.postgresql.org/docs/current/static/event-trigger-matrix.html
Have a look at this:
https://eager.io/blog/audit-postgres/
This is a quite simple, yet effective way to implement an auditing system, making use of the hstore data type. I recently tried it and it worked flawlessly "out of the box".
I am working with postgreSOL. I have a parent table and child table, which inherits the parent table.I create a trigger for the parent table. Is this trigger is propagated to child table? Any possible techniques to inherit the trigger also is available?
No, it isn't. You should write another trigger for the child table. Based on what your trigger should do, in same situations you can use the trigger on the parent table. For example, that trigger could decide in which table the data should go depending on some condition if an 'insert' query is made for the parent table.
I am using PostgreSQL 9.2 and I need to write an INSERT statement which copies data from table A to table B without firing the INSERT trigger defined on table B (maybe some sort of bulk insertion operation??).
On this specific table (table B) many INSERT, UPDATE and DELETE operations are executed. During each and every one of this executions, a trigger must fire.
I cannot temporary disable the triggers because of standard, day-to-day DML operations.
Can anyone help me with the syntax for this non-trigger-firing INSERT statement?
Run your "privileged" inserts as a different user. That way your trigger can check the current user and exit if it shouldn't do anything.
Sorry but I'm struggling with the online documentation.
What exactly is the difference for a FOR trigger compared to a AFTER and INSTEAD OF?
Thanks
The FOR and the AFTER trigger is the same. You specify them in the same way and they do the same thing:
CREATE TRIGGER sometrigger on sometable FOR INSERT,UPDATE,DELETE
CREATE TRIGGER sometrigger on sometable AFTER INSERT,UPDATE,DELETE
The INSTEAD OF trigger is something completely different. When you specify a trigger with the instead of then the trigger will execute instead of the insert, update and delete. This can be useful when you have views. So you can control what should be delete, updated and inserted in the views underlying tables
Here is an link to explain the triggers in more depth
Hi I am trying to figure out the syntax for triggers. I have two tables one called tagged_in and the other notification. So I want to make a trigger where when an insert is called in tagged_in I want to insert a tuple in notification.
The manuals are available at the DB2 InfoCenter. Did you read the CREATE TRIGGER statement information yet? If not, why not? If so, what did you try, and what error did you get?
Something like this
CREATE TRIGGER TEST_TRIGGER
AFTER INSERT ON TAGGED_IN
REFERENCING NEW AS NEW_TAG
FOR EACH ROW
BEGIN ATOMIC
INSERT INTO NOTIFICATION
VALUES (NEW_TAG.FIELD1,NEW_TAG.FIELD2);
END