Hands-on task
PostgreSQL: audit trigger
In the shop database there are empty tables products(id,name,price) and audit(id serial, msg text). Write a PL/pgSQL trigger function that, on every INSERT into products, adds a record to audit, and attach it as an AFTER INSERT trigger. Then insert one product — a record should appear in audit.
Write the function and the trigger as the SQL script /root/audit.sql in the Editor tab — multi-line PL/pgSQL reads much better in a file than in one command — and run it in the shop database.
- triggers
- pl/pgsql
- create function
- create trigger
- postgresql