postgreSQL Type of triggers
Trigger can be specified to fire:
• BEFORE the operation is attempted on a row - insert, update or delete;
• AFTER the operation has completed - insert, update or delete;
• INSTEAD OF the operation in the case of inserts, updates or deletes on a view.
Trigger that is marked:
• FOR EACH ROW is called once for every row that the operation modifies;
• FOR EACH STATEMENT is called onde for any given operation.
Preparing to execute examples
CREATE TABLE company (
id SERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
created_at TIMESTAMP,
modified_at TIMESTAMP DEFAULT NOW()
)
CREATE TABLE log (
id SERIAL PRIMARY KEY NOT NULL,
table_name TEXT NOT NULL,
table_id TEXT NOT NULL,
description TEXT NOT NULL,
created_at TIMESTAMP DEFAULT NOW()